mvvmkendo-uikendo-mvvmkendo-templatekendonumerictextbox

Kendo MVVM: How to bind a function to a Template inside a Template?


I prepared a simple dojo here: http://dojo.telerik.com/iQERE

Scenario:

I have an array within another array and I wanted to render it with a kendo template in a sort of table/grid. First array's items are the rows and inner array's items are the columns.

I Googled and found this technique: template inside template

The problems are:

1) How can I bind values for the nested array's items?

I tried data-bind="value:subval" but it doesn't work.

I think because using that technique the 'real data' of this template is the outer array, not the inner one!

Tried data-bind="value: item.subval" - leaded to nothing.

So finally I tried data-bind="value: subList[#:index#].subval" and it works. But I ask myself: Is this correct?

2) How can I bind the value to a function in the nested template? (famous kendo mvvm calculated fields).

I hoped I could bind all the input to a unique function who takes the 'caller' value and do something (multiply for another model field for example). But I can't get rid who called the function... my "e" argument is the whole data!

After some experiments I tried this way: http://dojo.telerik.com/OpOja and first time works... but it seems the function doesn't trigger when the value1 of the model change (which I would expect in a normal mvvm behavior), maybe because I declared the function inside the dataSource. (it's not an observable object itself?)

I hope I explained my problem well!


Solution

  • Well.. It seems is not possible. Response from a Telerik ticket: I am afraid, that the Kendo MVVM framework would not allow you to achieve the desired two-way binding for in the discussed scenario. The reason for that is the fact, that in the ​$.each() in the template would be executed only once and will not be reevaluated in the viewModel changes.

    In addition, in case you need to configure a hierarchical DataSource for an MVVM model, I would suggest you to follow this example. You will notice, that similarly to your implementation, it includes a field which is calculated as a function from another field. It however, will not allow you the desired two-way binding too. So the update of the value1 field would not trigger again the above mentioned function.