0

I have a backbone model which has custom parse function, while calling the fetch on this model sometimes I wanted to skip the parse function in certain scenarios. How can I do it. I tried the following option which did not work.

myModel.fetch({
            parse: false,
            success: _.bind(function(model, response) {}, this),
            error: _.bind(function(model, response) {}, this)
        });

My model code:

var MyModel = BaseModel.extend({
       initialize: function() {
       console.log('EventCloneModel in initialize()');
       _.extend(Backbone.Model.prototype, Backbone.Validation.mixin);
    },

    url: function() {
        var url = gc.apiUrl;
        var locale = "en_US"
        url += '&locale=' + locale;
        return url;
    },

     parse: function(response) {
          //some parsing logic goes here
          return response;
       },


    getValidations: function(){
      return this.validation;
    }

  });

  return MyModel;

});
user1614862
  • 3,701
  • 7
  • 29
  • 46
  • 1
    That's weird, because if you have a look at the Backbone source (perhaps you did), the `parse: false` option does exactly what you need. Maybe the problem is elsewhere? – hashchange Sep 02 '16 at 07:31
  • It looks like my version of backbone doesn't have it.(0.9.x) – user1614862 Sep 07 '16 at 22:55

1 Answers1

0

Put the skip condition in your parse function. How you determine the skip condition is up to you.

parse: function(response) {
      if(skipParse)
          return response;
      //parse the response here. If the code reaches this point, 
      //it means you want to parse it.
      return response;
   },
Eric Guan
  • 15,474
  • 8
  • 50
  • 61