我正在尝试使用 knockout.js UI 更改内存中的 JSON。我遇到的问题是,当我更改 UI 中的值时,JSON 数据似乎没有任何变化。我已经用 console.log(config) 实现了按钮来测试它。任何建议都会很棒,谢谢!
编辑.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());