【发布时间】:2015-05-12 01:52:22
【问题描述】:
我有这个模型:
var child = function(c){
var self = this;
self.id = ko.observable(c.id);
self.first_name = ko.observable(c.first_name);
self.last_name = ko.observable(c.last_name);
self.gender_id = ko.observable(c.gender_id);
self.birthday= ko.observable(c.birthday);
self.family_id = ko.observable(c.family_id);
}
我有一个这样定义的视图模型:
var childrenViewModel = function(initialData){
var self = this;
//
self.children = ko.observableArray(initialData);
//
self.removeChild = function(){};
};
我以这种方式获取初始数据:
$.ajax({
type: 'GET',
url: getChildrenListUrl,
contentType: 'application/json'
})
.done(function (data) {
vmChildren =new childrenViewModel(JSON.parse(data));
ko.applyBindings(vmChildren,document.getElementById('portlet-children'));
Metronic.unblockUI('#portlet-children');
});
我现在想通过使用映射插件来制作孩子 observablearray 的内容,可观察自己,但我在这样做时遇到了困难......
【问题讨论】:
标签: knockout.js knockout-mapping-plugin