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

前端 未结 2 896
小蘑菇
小蘑菇 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:37

    I worked around this by using value: $parent.list[$index()], as seen in this jsFiddle. The new bindings looks like this:

    One could perhaps improve on this with a custom binding.

    See also this related GitHub issue #708 for Knockout.js.

    Update for Knockout 3.0:

    Knockout now provides $rawData:

    creates a two-way binding as expected.

    From the Binding Context documentation:

    $rawData

    This is the raw view model value in the current context. Usually this will be the same as $data, but if the view model provided to Knockout is wrapped in an observable, $data will be the unwrapped view model, and $rawData will be the observable itself.

提交回复
热议问题