2

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

http://jsfiddle.net/Hfwfs/1/

编辑.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());
4

1 回答 1

2

它正在更新,您必须查看模型

在此处输入图像描述

于 2013-09-18T18:52:30.750 回答