使用knockout更新嵌套的JSON

时间:2013-09-18 18:33:39

标签: javascript json knockout.js

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

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

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());

1 个答案:

答案 0 :(得分:2)

它正在更新,您需要查看模型

enter image description here