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

Re : Data not converted to observable?

$
0
0
If you want to keep them separate instead of having if conditions in findAll or findOne, then you can call .model or .models inside the custom finder method to convert raw data to model objects

findCustom : function(params){
      var thisclass = this;
      var deferred = can.Deferred();
      var findCustomDeferred = can.ajax(//settings);
      findCustomDeferred.then(function(raw, textStatus, jqXHR){
            var model = thisclass.model(raw);
            deferred.resolve(model, textStatus, jqXHR);
      }, function (jqXHR, textStatus, errorThrown) {
            // log error
            deferred.reject(jqXHR, textStatus, errorThrown);
      });
}

You can use the same approach if you want to do deepFetch by making multiple api calls construct the model object.

Viewing all articles
Browse latest Browse all 3491

Trending Articles