簡體   English   中英

如何在調用訪存時跳過骨干模型中的解析函數調用

[英]How to skip parse function call in backbone model while calling fetch

我有一個具有自定義解析功能的骨干模型,而有時在某些情況下我想跳過該解析函數,同時在此模型上調用提取。 我該怎么做。 我嘗試了以下無效的選項。

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

我的模型代碼:

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;

});

將跳過條件放入解析函數中。 如何確定跳過條件取決於您。

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;
   },

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM