How to replace a given index element in knockoutjs

后端 未结 5 596
时光说笑
时光说笑 2020-12-15 04:55

How do you replace a given index in an observableArray with another element.

I have: ViewModel.Elements()[index]

how can i replace it with anot

5条回答
  •  有刺的猬
    2020-12-15 05:04

    Editing the underlying array and reassigning it did the trick for me. I had trouble with other approaches.

    var underlyingArray = this.someObservableArray();
    
    // Do modifications... Swap some items...
    // No one is being notified just yet...
    
    // Reassign to observable to update everything
    this.someObservableArray(underlyingArray);
    

提交回复
热议问题