Notify observableArray of item change

1,967 views
Skip to first unread message

bennyhill

unread,
Jul 3, 2011, 8:46:17 PM7/3/11
to KnockoutJS
I have objects with observable properties in a single
observableArray. How can I notify the array that a property on a
single object in the array has changed? For example, if sam's name
changes.

var Person = function (name){
return { name: ko.observable(name) }
}

var viewModel = {
people: observableArray([new Person('sam'), new Person('mary') ])
}

Mark Bradley

unread,
Jul 3, 2011, 8:59:19 PM7/3/11
to knock...@googlegroups.com
Observable arrays are really just an extended form of observable, and
there is a function on observables:
valueHasMutated:
https://github.com/SteveSanderson/knockout/blob/master/src/subscribables/observable.js#L29
that will perform the necessary notifications.

e.g.
viewModel.people.valueHasMutated();

--
-barkmadley
sent from an internet enabled device
http://barkmadley.com

Reply all
Reply to author
Forward
0 new messages