我正在尝试使用knockout.js UI更改内存中的JSON。我遇到的问题是,当我在UI中更改值时,JSON数据似乎没有任何改变。我用console.log(config)实现了按钮来测试它。任何建议都会很棒,谢谢!
edit.js
var config = {
"departments": [
{
"name": "Step Down"
}, {
"name": "ER"
}]
};
var DepartmentViewModel = function (dep) {
var self = this;
self.name = ko.observable(dep.name);
}
function ConfigViewModel() {
var self = this;
self.departments = ko.observableArray([]);
ko.utils.arrayForEach(config.departments, function (dep) {
self.departments.push(new DepartmentViewModel(dep));
});
}
ko.applyBindings(new ConfigViewModel());
答案 0 :(得分:2)
它正在更新,您需要查看模型