This is a migrated thread and some comments may be shown as answers.

Why is kendo.bind needed?

6 Answers 52 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Norm
Top achievements
Rank 1
Norm asked on 26 Apr 2013, 06:13 PM
I am using declarative binding like so:
<div id="main" data-role="view" data-model="viewModel">
Foo: <span data-bind="text: bar"></span>
</div>

Since I specified data-model I would expect 'bar' to be binded, but that's not the case. It doesn't work.

It only comes together when I call kendo.bind('#main', viewModel).

Do I always need to call kendo.bind() for all of my viewModels to work?

6 Answers, 1 is accepted

Sort by
0
Norm
Top achievements
Rank 1
answered on 26 Apr 2013, 07:16 PM
It looks automatic binding through data-model only works for mobile apps when you call new kendo.mobile.Application().

Is this right?
0
Atanas Korchev
Telerik team
answered on 29 Apr 2013, 07:26 AM
Hello Norm,

 Yes, kendo.mobile.Application internally calls kendo.bind when the model data attribute is set. If you are not using kendo.mobile.Application you must call kendo.bind. You can find more info about Kendo MVVM in the related documentation: http://docs.kendoui.com/getting-started/framework/mvvm/overview

Kind regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Norm
Top achievements
Rank 1
answered on 29 Apr 2013, 01:45 PM
Is there any downside if I use kendo.mobile.Application() if I am not building a mobile application?

I like the idea of having my binds auto-initialized.
0
Atanas Korchev
Telerik team
answered on 30 Apr 2013, 07:52 AM
Hi Norm,

 Initializing a kendo.mobile.Application does the following:

1. Attached event handlers for various events
2. Adds various CSS classes to page elements
3. Appends meta tags for the viewport configuration
4. Listens for browser history changes

 Those may create quite a few side effects if you are not building a Kendo UI Mobile application.

I may suggest creating a helper method which will bind a DOM element to its model data attribute:

function bind(element) {
   var modelName = $(element).data("model");
   var model = window[modelName];
   kendo.bind(element, model);
}


Then you can use it like this:

<div id="view" data-model="myViewModel"></div>
<script>
var myViewModel = kendo.observable({});
bind($("#view"));
</script>

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Nathan
Top achievements
Rank 2
answered on 29 May 2013, 04:35 PM
With absolutely no offence intended, couldn't you just fix the product so we don't have to use a workaround?

(To be fair I could have put that comment on about half the forum posts)
0
Atanas Korchev
Telerik team
answered on 29 May 2013, 04:41 PM
Hello Nathan,

I am not sure what problem needs fixing in this particular thread. I don't see any bug being discussed here. The requested behavior is just not supported/implemented and a viable solution is suggested.

I recommend opening a new feature request in our feedback portal. If it gathers interest we would consider it for our future plans.

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
MVVM
Asked by
Norm
Top achievements
Rank 1
Answers by
Norm
Top achievements
Rank 1
Atanas Korchev
Telerik team
Nathan
Top achievements
Rank 2
Share this question
or