aikeru
aikeru

Reputation: 3983

Kendo MVVM custom widget: accept object as parameter

When developing a custom Kendo MVVM widget, passing a simple data-bound parameter seems fine, whether in a custom binding. IE:

<div data-bind="value: simpleParameter">This works fine</div>

<div data-bind="mybinding: simpleParameter">This also works fine</div>

I notice the css and events bindings can accept objects as parameters. I really want to accept objects as parameters too, but when I try, it throws an error:

<div data-role="mycomponent" data-bind="value: { prop: value }">This throws</div>

<div data-role="mycomponent" data-bind="mybinding: { prop: value }">This throws too</div>

In the case of the custom binding, it doesn't throw until I try accessing the value. I've tried it like...

var arg = this.bindings["mybinding"].get();

...and other variations, but nothing seems to work. Is it possible to accept objects like { prop: value, prop2: value2 } for custom Kendo UI widgets in their MVVM framework?

Upvotes: 0

Views: 419

Answers (1)

Brett
Brett

Reputation: 4269

Your answer is in this article, Making Kendo UI Binders for Complex Types.

If you have tried to make a binder like this yourself, you have probably run into issues. Kendo actually does not provide support for these complex bind paths for custom binders.

Basically, Kendo UI expects your expressions to be a string representation of a variable or function name, not a complex object. What you have to do is call this.bindings.class.get() multiple times to retrieve the values you need.

To get these values for the get() function to read, you'll create a list of key/value pairs from the complex object in the binding's init() constructor method. Then, in your binding's refresh() method, you simply iterate over this list and call get().

Upvotes: 1

Related Questions