KnockoutJS - Observable Array of Observable objects

后端 未结 3 1317
清酒与你
清酒与你 2020-12-09 07:59

I would like to display an editable list of items, each item of which is editable (kind of like an editable grid, in a way). I am using KnockoutJS. I cannot use just a simpl

3条回答
  •  春和景丽
    2020-12-09 08:50

    ko.utils.arrayMap doesn't map your viewmodel's properties as observables, and that's why you don't see them updated dynamically.

    If you define your CategoryId as an observable, you'll see it update as expected:

    var initialData = [
        {
            Name: "Television",
            CategoryId: ko.observable("1")
        },
        {
            Name: "Melon",
            CategoryId: ko.observable("2")
        }
    ];
    

    See this updated jsfiddle: http://jsfiddle.net/tuando/E7xPM/5/

提交回复
热议问题