1
votes

I am having an issue with Knockout which seems a bit puzzling.

I have a list of contacts, which I want to bind to the UI (observableArray).
However I do not need the items themselves to each be observable, since they are only updated through a dialog box and I don't need each field tracked separately.

I have the following jsFiddle to demonstrate my issue:

http://jsfiddle.net/EsgGg/12/

var c = contacts()[0];
c.name="James";
contacts.splice( 0, 1, c ); 
// the contacts observableArray is now correct but the UI is unchanged

For some reason the splice method does not update the View??

Thanks in advance.

I really think that Knockout should allow a trigger('change') or some other method on observables to make this type of thing easier.

1

1 Answers

2
votes

Knockout has a change trigger on observables. It's called valueHasMutated()

contacts.valueHasMutated();

But in fact you are better off if every value that shows on the screen (and is subject to occasional change) is an actual observable in your view model.

contacts()[0].name("James");  // done