我遇到了返回子节点的问题,好像它不想绑定。
这是jsFiddle http://jsfiddle.net/gnpoe6a6/2/
var viewModel = {
model: ko.mapping.fromJS(data),
people: ko.mapping.fromJS([]),
loadInitialData: function() {
ko.mapping.fromJS(data, dataMappingOptions, viewModel.people);
}
};
答案 0 :(得分:1)
你应该这样做。
查看型号:
var viewModel = function(data){
this.name =ko.observable();
this.array=ko.observableArray();
ko.mapping.fromJS(data, mapping,this);
this.loadInitialData=function(){
this.array(ko.mapping.fromJS(data, mapping,this).TM1ChoreProcessRel());
console.log(this.array());
}.bind(this);
};
var data = {//you json Data};
var Person = function(data) {
this.ID = ko.observable();
this.Name = ko.observable();
this.ParemeterValues = ko.observable();
ko.mapping.fromJS(data, mapping, this)
};
var mapping = {
create:function(options){
return new Person(options.data);
},
'TM1ChoreProcessRel': {
create: function(options) {
return ko.mapping.fromJS(options.data);
}
}
}
ko.applyBindings(new viewModel(data));
Wokring小提琴 here