steveluscher / knockout.meteor

A Knockout-to-Meteor bridge
http://steveluscher.github.com/knockout.meteor
MIT License
66 stars 10 forks source link

Added data transform option #2

Closed kenpratt closed 12 years ago

kenpratt commented 12 years ago

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).

steveluscher commented 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 } );
kenpratt commented 12 years ago

Thanks, got it working using update as you suggested.