Closed kenpratt closed 12 years ago
I'm pretty sure that the Knockout Mapping plugin allows you to declare mappings that perform these kinds of transforms.
var myMapping = {
phone_numbers: {
update: function(options) {
var array = _.map(options.data, function(v,k) { return { place: k, number: v }; } )
return ko.observableArray(array);
}
}
}
ko.meteor.find( People, {}, { mapping: myMapping } );
Thanks, got it working using update as you suggested.
Hey, I added an option to let you transform the data before passing it into Knockout Mapping.
This lets you do stuff like store nested hashes in Mongo (which are great for querying there), but then convert them to arrays before passing into Knockout Mapping so they become ObservableArrays (which are great for binding).