How to bind Parent/Sub-Elements correctly?

4 posts, 0 answers
  1. fbaptiste
    fbaptiste avatar
    19 posts
    Member since:
    Apr 2007

    Posted 19 Sep 2014 Link to this post

    I have the following Scenario

    HTML
    <div id="dashboard" data-bind="visible: isVisible">
        <div id="widget1" data-bind="visible: isVisible">
        <div id="widget2" data-bind="visible: isVisible">
    </div>
     
    JS
     $(function () {
        var dashboardVM: ObservableObject{
            isVisible: true
        };
        kendo.bind('$("#dashboard")', dashboardVM);
         
        var widgetVM: ObservableObject{
            isVisible: false
        };
        kendo.bind('$("#widget1")', widgetVM);
     }

    My intention is that dashboard and any unbinded sub element are binded to DashboardVM fields, UNLESS there is a specific VM binded to that sub element. in this case 'widget1' fields binded should come from widgetVM.
  2. Petyo
    Admin
    Petyo avatar
    2439 posts

    Posted 23 Sep 2014 Link to this post

    Hi Fred,

    binding the same tree to multiple view models is not a supported scenario (and, I would not recommend it for that matter). The recommended approach in this case is to create a composite view model, which will hold the fields for each section. 

    Regards,
    Petyo
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
  4. fbaptiste
    fbaptiste avatar
    19 posts
    Member since:
    Apr 2007

    Posted 23 Sep 2014 in reply to Petyo Link to this post

    Could you please post a recommended example for this based on the scenario that i have?
  5. Petyo
    Admin
    Petyo avatar
    2439 posts

    Posted 25 Sep 2014 Link to this post

    Hello,

    If I understand your requirements correctly, something like this should do the trick.

    Regards,
    Petyo
    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