Knockout.js using `value:` binding in a `foreach` over a list of strings - does not update

前端 未结 2 833
小蘑菇
小蘑菇 2021-02-14 00:03

Here is a jsFiddle demonstrating the following problem:

Given a foreach binding over a list of (observable) strings, the observables do not seem to update from changes t

2条回答
  •  北海茫月
    2021-02-14 00:20

    Every data object used in the default knockout bindings will always be unwrapped. So you are essentially binding to the value of the items in the list, not the observable as you are expecting.

    Observables should be properties of an object, not a replacement of the object itself. Set the observables as a property of some object so this doesn't happen.

    ​var vm = {
        list: [
            { value: ko.observable('123') },
            { value: ko.observable('456') }
        ]
    };
    

提交回复
热议问题