0
我有一個骨幹視圖,我調用model.save來創建/更新表單中提交的日期。在調用save之前,我顯式調用了model.isValid(true)來驗證表單字段,然後處理表單數據以使其準備API預期格式(通過添加或修改附加字段),然後調用mode.save函數由於修改後的數據,再次觸發驗證功能,驗證功能失敗。因爲我已經明確地調用了isValid函數,所以我想在保存期間再次阻止該調用。我怎麼能在骨幹中做到這一點。這裏是示例代碼。如何在骨幹JS中調用model.save時防止驗證函數調用
var data = Backbone.Syphon.serialize($(e.currentTarget).closest('form.my_form')[0]));
this.model.set(data);
if(this.model.isValid(true)) {
data['metas'] = this.context.metaData;
data['metas'][0]['locale'] = this.parentObj.model.get('locale');
data['metas'][0]['name'] = data['name'];
delete data['name'];
}
var tempDynAttrs = [];
if(data['dynamicAttributes']){
$.each(data['dynamicAttributes'], function(index,obj) {
if(obj['attributeValue'] !== null && obj['attributeValue'] !== undefined) {
tempDynAttrs.push({
attributeName: obj['attributeName'],
attributeValue: [obj['attributeValue']],
locale: data['defaultLocale'],
status: 'active'
});
}
});
}
data['dynamicAttributes'] = tempDynAttrs;
this.model.save(data, {
url: this.model.url(),
patch: true,
success : function(model, response) {
$('#headerMessage').html('Data is updated successfully');
},
error : function(model, response) {
$('#headerMessage').html('Error updating data');
}
});
} else {
$('#formPanel').animate({
scrollTop: $('.has-error').first().offset().top-50
}, 100);
return false;
}