Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : Best/most effcient way to modify/augment model list data returned after findOne/findAll

$
0
0
Alternately, you can override can.Model.models/can.Model.model to do preprocessing on all data that comes back through the declarative layer (i.e. for findAll, findOne, create, and update):

  1. findAll : "GET /things"
  2. , models : function(rawlist) {
  3.   
  4.   // Do whatever on the list
  5.   return this._super(rawlist);  // this mostly just calls model() on each element to make an instance, but in a very 
  6.                                          // type-safe and efficent way around the source list.
  7. }
  8. , model: function(rawthing) {
  9.   // Do whatever to each rawthing
  10.   return this._super(rawthing); // to modelize the raw object
  11. }
Advantage of doing it this way is that you can make changes in superclasses that are respected and added to in subclasses.  Disadvantage is that you can't distinguish whether the raw lists/objects came through findAll, findOne, update, or create.

Viewing all articles
Browse latest Browse all 3491

Trending Articles