I have some parent container which is bind to ViewModel#1. This container contains other child container that is bind to ViewModel#2.
I’m not sure yet, but it looks like whole content of child container is bind to ViewModel#1 ONLY.
Is it possible to have such type of binding (having nested views) in Kendo? Would it have some potential issues with binding in that case? (Ambiguous bindings, issues when perform binding, etc.)
If it is not possible, what approach would you recommend?
6 Answers, 1 is accepted
To avoid potential problems I recommend you to exclude the child container during the initial binding (you may have to use a little more complex jQuery selector for this task). For your convenience I prepared a small example: http://jsbin.com/ipisuh/4/edit
the Telerik team
The solution proposed works great, but not for all the cases.
In case if parent container which has children to be excluded it is Kendo widget and it needs to be bind itself to View Model – we cannot exclude container from binding.
Kendo.bind traverses all children of container if we include it into binding. So jQuery selector doesn’t help here.
Real world example:
Kendo Tabstrip is bind to ViewModel and its widget properties are bind to appropriate properties in viewModel.
However tabs are loaded from other views which have own ViewModels.
Can you please recommend the solution here?
I am afraid that I cannot understand the exact specification of your scenario. Generally speaking, what you would like to achieve is not supported - if you bind the widget's container twice, the widgets will be initialized twice (because they have data-role) which may cause troubles.
Thank you in advance for the cooperation.
the Telerik team
This is Orest, I’m working in the same team as Andriyan.
Let me explain our case in the details:
- Kendo ASP.NET MVC wrappers are used in my solution
- Kendo TabStrip is formed for every page dynamically, and tabs are separate ASP.NET MVC views
- TabStrip has own viewModel that allows binding to tab selection events and other TabStrip properties.
- Each view is bind to separate ViewModel and it contains own specific logic (Combining views into one viewModel is just impossible, as number of views is large)
- Basically I want to load the TabStrip and Views with one request from server.
In this case I have issues with binding because Parent container is bind when it has Child views (tabs) inside of its DOM.
- In case Views are loaded asynchronously after TabStrip is loaded – binding work, however that leads to other possible issues with asynchronous handling \synchronization of views, their logic, so on.
It really is painful.
So it’s better to load the TabStrip and Views with one request from server. However it’s not possible now because of binding issues.
Please take a look http://jsbin.com/ohozel/1/edit for simple example (with TabStrip and tabs). Of course it doesn’t reflect fully my case – as it has lots of Server-side logic. However it illustrates the issues with bindings on tabstrip.
The issue actually is because we cannot bind TabStrip itself to ViewModel ( without parsing the children).
If Kendo would provided Kendo.bind with “TraverseChildren” option – it would be great.
This is currently not supported. I can suggest to submit this as feature request in our user voice forum. If the idea is popular we will consider it for future versions.
For now I can suggest either to add the tabstrip or its tabs content dynamically after the main viewModel is bound. If using Ajax to load the tabs content, I can suggest to force the content to be loaded after the tabStrip initialization:
the Telerik team