我一直在尝试了解backbone.js,我只是尝试在https://tutsplus.com/lesson/validating-models/上学习如何验证模型的教程,但由于某种原因,我的代码只是不'验证
知道为什么会这样吗?
var Person = Backbone.Model.extend({
defaults: {
name: 'John Doe',
age: 30,
occupation: 'worker'
},
validate: function (attrs) {
if (attrs.age <= 0) {
return "age must be positive";
}
if (!attrs.name) {
return "every person must have a name";
}
},
work: function () {
return this.get('name') + ' is working.';
}
});
有人可以帮忙吗?代码有什么问题吗?