Why is kendo.bind needed?

7 posts, 0 answers
  1. Norm
    Norm avatar
    12 posts
    Member since:
    Apr 2013

    Posted 26 Apr 2013 Link to this post

    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?
  2. Norm
    Norm avatar
    12 posts
    Member since:
    Apr 2013

    Posted 26 Apr 2013 Link to this post

    It looks automatic binding through data-model only works for mobile apps when you call new kendo.mobile.Application().

    Is this right?
  3. Kendo UI is VS 2017 Ready
  4. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 29 Apr 2013 Link to this post

    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!
  5. Norm
    Norm avatar
    12 posts
    Member since:
    Apr 2013

    Posted 29 Apr 2013 Link to this post

    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.
  6. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 30 Apr 2013 Link to this post

    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!
  7. Nathan
    Nathan avatar
    39 posts
    Member since:
    Sep 2011

    Posted 29 May 2013 Link to this post

    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)
  8. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 29 May 2013 Link to this post

    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!
Back to Top
Kendo UI is VS 2017 Ready