我的视图模型中有以下函数来构建可观察数组的动态数组,由 item.array_name 字段命名。但是,我在用 Document 对象填充数组时遇到了困难。因此,我在每个数组的页面内多次重复使用相同的 HTML 界面。有人可以指出我出错的方向,还是他们的更好方法?
self.getDocument = function(){
//Reset arrays
self.documents.removeAll();
//Dynamically build arrays
$.getJSON("/Documentation/Get-Section", function(allData) {
$.map(allData, function(item) {
var obj = {};
obj[item.array_name] = ko.observableArray([]);
self.documents(obj)
})
});
//Add document object to the arrays
$.getJSON("/Documentation/Get-Document", function(allData)
$.map(allData, function(item) {
var temp_array = 'self.documents.'+item.array_name
eval(temp_array+'(new Document(item))')
});
});
}