Computed values as children of ko.observableArray

1,759 views
Skip to first unread message

Jackson Murtha

unread,
May 29, 2012, 1:35:23 AM5/29/12
to knock...@googlegroups.com
Hello,
   I haven't been able to successfully use dependent observables as elements in an observable array, and I haven't been able to find any examples of this either.  It seems basic, can anyone point me in the right direction?

Here is a simple js fiddle:
http://jsfiddle.net/jacksonmurtha/XnZNs/

When updating the 'name' property of the child objects, I would expect the fullName property to update, but I'm obviously on the wrong track.

Thanks in advance for any help/examples
jxn

rpn

unread,
May 29, 2012, 8:39:28 AM5/29/12
to knock...@googlegroups.com
Hello-
There are several ways to handle your case.  Here is one: http://jsfiddle.net/rniemeyer/XnZNs/1/.  computed observables will depend on any observables that have their value accessed during its evaluation.  In your case, you were reading the non-observable properties off of the original child objects.  You would want to create your observables and then create a computed observable that accesses them.  Hope this helps.

Jackson Murtha

unread,
May 30, 2012, 3:15:02 PM5/30/12
to knock...@googlegroups.com
Thanks Ryan, that was very helpful.  I've got the paradigm a lot better now and have refactored my test application to take advantage.

Thanks again!


On Tuesday, May 29, 2012 12:35:23 AM UTC-5, Jackson Murtha wrote:
Reply all
Reply to author
Forward
0 new messages