当我调用我的骨干模型时,即使是否满足验证规则,isValid()
它也会始终返回。undefined
这里可能出了什么问题?
这里可能是什么问题,我该如何解决?
我的模型:
Backbone.Model.extend({
validation: {
firstname: { required: true, msg: _('First Name is required').translate() }
, lastname: { required: true, msg: _('Last Name is required').translate() }
}
});
我的观点:
Backbone.View.extend({
events: {
'submit form[data-action="specify-pbt"]': 'specifyPBT'
}
, bindings: {
'[name="firstname"]': 'firstname'
, '[name="lastname"]': 'lastname'
}
, initialize: function(options) {
this.model = options.model || new PBTSpecifyModel(); // The latter condition is always met
BackboneCompositeView.add(this);
BackboneFormView.add(this);
Backbone.Validation.bind(this);
}
, specifyPBT: function (e)
{
var options = jQuery(e.target).serializeObject();
console.log("model: ");
console.log(this.model); // Outputs the model: looks all correct
console.log("isValid: ");
console.log(this.model.isValid()); // Outputs undefined
console.log("validationError: ");
console.log(this.model.validationError); // Outputs null
}
, getContext: function()
{
return {
}
}
})
});