如何在调用 fetch 时跳过 backbone 模型中的解析函数调用
How to skip parse function call in backbone model while calling fetch
我有一个 backbone 模型,它具有自定义解析函数,在调用此模型上的提取时,有时我想在某些情况下跳过解析函数。我该怎么做。我尝试了以下无效的选项。
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;
},
我有一个 backbone 模型,它具有自定义解析函数,在调用此模型上的提取时,有时我想在某些情况下跳过解析函数。我该怎么做。我尝试了以下无效的选项。
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;
},