I'm new to KnockoutJS, and I'm stuck trying to add additional properties and methods to the generated objects in the ko.observableArray()
as created by the mapping
plugin.
Here's where I'm up to:
- I have a JSON array of
Users
- I've created the
ko.observableArray()
with the mapping plugin - I've got a template that creates table row for each
User
, so far so good :o)
Here's what I'm trying to do:
Each User
has a property called 'IsActive'
- I'd like to data-bind
a click event to a method on each User
object that toggles this 'IsActive'
property.
This question looked promising, but it seems like unnecessary duplication to me to have to declare the entire View Model in JS (unless that's the way I have to do it!) - is it possible to just extend the generated object?
I was thinking more along these lines, where there's a way to declare additional properties or methods, and have them extend the mapping
generated objects, but this article is concerned with single objects rather than extending objects in a generated array.
Here's the code: http://jsfiddle.net/yZkSf/2/ (not yet working in JS fiddle - but I'll keep playing with it and update this link when I get it working).
create:
callback, but the documentation focuses on modifying a child array, and I couldn't see how to augment the base object. Thank you so much – Jodeejodhpur