mardi 5 mai 2015

Use underscore.js "pluck" on a knockout observable array

I have an observable array of objects and I want to pluck out the values using underscore.js

For example:

ko.observableArray([{
  id: ko.observable(1),
  name: ko.observable("name1")
},
{
  id: ko.observable(2),
  name: ko.observable("name2")
},
...])

And I just want to pluck the values inside of the object rather than the whole observable.

Can I do this with just one command?

I tried:

_.pluck(myArray(), "id()") and _.pluck(myArray(), "id"())

But these return an array of undefineds and "id is not a function" respectively.

Thanks!

Aucun commentaire:

Enregistrer un commentaire