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

How to bind Parent/Sub-Elements correctly?

3 Answers 100 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
fbaptiste
Top achievements
Rank 1
fbaptiste asked on 19 Sep 2014, 06:02 PM
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.

3 Answers, 1 is accepted

Sort by
0
Petyo
Telerik team
answered on 23 Sep 2014, 12:57 PM
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!
 
0
fbaptiste
Top achievements
Rank 1
answered on 23 Sep 2014, 05:26 PM
Could you please post a recommended example for this based on the scenario that i have?
0
Petyo
Telerik team
answered on 25 Sep 2014, 08:52 AM
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!
 
Tags
MVVM
Asked by
fbaptiste
Top achievements
Rank 1
Answers by
Petyo
Telerik team
fbaptiste
Top achievements
Rank 1
Share this question
or