0
 <pre data-bind="text: ko.toJSON($data, null, 2)"></pre>

    <ul data-bind="foreach: arrData" >
        <li>  
            <span data-bind="text: name"></span>
        </li>
    </ul>

The structure is like $data.arrData which arrData is an observablearray. I modify the contents like this:

arrData().splice(0, 1, ko.toJS(data.selectedData)); 

The $data variable does update but not the observableArray. But if I insert in the array in the beginning then the old value shows, but not the new one.

1
  • can you add a sample fiddle explaining the issue or try arrData.splice(//). Commented Oct 21, 2015 at 15:30

1 Answer 1

3

by reading the value of arrData using arrData() you're falling back to the underlying array. It seems you want to be using the version of splice directly on the observable array itself:

arrData.splice(0, 1, ko.toJS(data.selectedData)); 
Sign up to request clarification or add additional context in comments.

3 Comments

And what's the solution?
Uhm... exactly what I posted (remove the parentheses from arrData())
Alternatively you could achieve the same by doing: var temp = arrData(); temp.splice(0, 1, ko.toJS(data.selectedData)); arrData(temp);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.