I was trying to make a knockout mapped JSON schema editor in table format. I successfully mapped json object, but issue is when i'm dealing with json array.
Code
var l_Model;
//Create model
l_Model = function(l_data) {
var self = this;
//map data from json as observables
ko.mapping.fromJS(l_data, {}, self);
//observable to get equation from json
self.Eqn = ko.observable(null);
};
//view model mapping to html
var viewModelMapping = {
'dataModel': {
create: function(options) {
return new l_Model(options.data);
}
}
};
var vm = ko.mapping.fromJS(Data);
This code works as long as data is
data = {}
But When I deal with array of json objects I'm not able to map it
data =[{},{},{},.....]
I'm getting error in the console
Uncaught ReferenceError: Unable to parse bindings.
asked Aug 7, 2013 at 5:28
Okky
10.5k16 gold badges78 silver badges123 bronze badges
1 Answer 1
You can map your object from the root of the array and process each item and separated objects. You can even have another mapper inside your object and continue processing data with nested mappers
//mapper method
mapCollection = {
'': {
create: function (options) {
return new objectWithAnotherMapper(options.data);
}
}
},
answered Aug 7, 2013 at 11:23
Pablo Rodríguez
4461 gold badge3 silver badges8 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Explore related questions
See similar questions with these tags.
lang-js
l_row += "<td class='seRow'><span data-bind='text: $root[" + index + "]." + key + "'/><textarea rows='1' data-bind='value: $root[" + index + "]." + key + "' /></td>";The first row will display the right values