KoGrid update cell

二次信任 提交于 2019-12-24 00:41:22

问题


I am trying to update a single cell with KoGrid, but I don't see the update happen until I sort the grid by clicking on the column header.

The following is the code I'm using. JSFiddle available here: http://jsfiddle.net/b22Ex/2/

The line that's not working is: vm.data()[0].b(100). Shouldn't that work since the value is a ko.observable?


    var L = [
        {a:ko.observable('a1'), b:ko.observable('b1'), c:ko.observable('c1')},
        {a:ko.observable('a2'), b:ko.observable('b2'), c:ko.observable('c2')},
        {a:ko.observable('a3'), b:ko.observable('b3'), c:ko.observable('c3')}
    ];
    var vm = {
        data: ko.observableArray(L)
    };
    window.vm = vm;
    ko.applyBindings(vm);
    vm.data()[0].b(100)
    console.log("DONE CHANGING VALUE");


By the way, I also came across KoGrid how to refresh grid in case data is changed but I don't want to update the entire dataset.


回答1:


Updated

Try this :

Working Fiddle

JS

var xxx = [
    {a:ko.observable('a1'), b:ko.observable('b1'), c:ko.observable('c1')},
    {a:ko.observable('a2'), b:ko.observable('b2'), c:ko.observable('c2')},
    {a:ko.observable('a3'), b:ko.observable('b3'), c:ko.observable('c3')}
];

var vm = {
    data: ko.observableArray(xxx),
};

window.vm = vm;
ko.applyBindings(vm);

 vm.data()[0].b(100);
 vm.data.valueHasMutated();  //This will update your observable in UI


console.log("DONE CHANGING VALUE");



回答2:


Below is the solution to your problem. Check this Fiddle.

var xxx = [
 {a:ko.observable('a1'), b:ko.observable('b1'), c:ko.observable('c1')},
 {a:ko.observable('a2'), b:ko.observable('b2'), c:ko.observable('c2')},
 {a:ko.observable('a3'), b:ko.observable('b3'), c:ko.observable('c3')}
];
var vm = {
 data: ko.observableArray(xxx)
};
window.vm = vm;
ko.applyBindings(vm);
vm.data()[0].b(100)

vm.data(vm.data()); //This line will make the fix that you need.

console.log("DONE CHANGING VALUE");


来源:https://stackoverflow.com/questions/15798881/kogrid-update-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!