knockout.viewmodel
knockout.viewmodel copied to clipboard
Syntax for extending viewmodel with repeating sequence of members
I have a view model that consists of an object having a member of the same type, that can repeat an arbitrary number of times before terminating:
var data = { 'myobject' : { 'amember': avalue, 'myobject' : { 'amember: avalue, 'myobject' : { ... ...
Currently I extend this model using ko viewmodel options:
var options = { extend: { "{root}.myobject": function(myobject) { init(myobject); }, "{root}.myobject.myobject": function(myobject) { init(myobject); }, ... "{root}.myobject.myobject.myobject.myobject.myobject": function(myobject) { init(myobject); }, } }
Which works fine as long as my data doesn't have the sequence of members repeat more than 5 times (in this example).
If would be great if there were a syntax to take care of this automatically. Perhaps something like:
"{root}.myobject...": function(myobject) {
init(myobject);
},
And also be able to handle arrays (which is actually the real scenario with my model):
"{root}.myobject[i]...": function(myobject) {
init(myobject);
},
By providing such a syntax and implementation would allow for this kind of a model that could handle any arbitrary depth of repeating members, which is clearly desirable.
Thanks for considering this.