안녕하세요, 백본의 유효성 검사가 바뀌 었음을 알고 작업을 수행하려고합니다. 누군가는 무엇이 잘못되었는지 알아 차립니다. 유효성을 검사하는 JSfiddle 링크도 있습니다. 유효성을 검사하지 않는 이유를 이해하지 못합니다. http://jsfiddle.net/NcHTb/백본에서 유효성 검사가 유효하지 않습니다?
은 코드 :
(function() {
window.App = {
Models: {},
Collections: {},
Views: {},
Templates: {},
Router: {}
};
App.Models.User = Backbone.Model.extend({
defaults: {
firstName: 'first',
lastName: 'last',
email: 'Email',
phone: '222',
birthday: 'date'
},
validate: function (attrs) {
if (!attrs.firstName) {
return 'You must enter a real first name.';
}
if (!attrs.lastName) {
return 'You must enter a real last name.';
}
if (attrs.email.length < 5) {
return 'You must enter a real email.';
}
if (attrs.phone.length < 10 && attrs.phone === int) {
return 'You must enter a real phone number, if you did please remove the dash and spaces.';
}
if (attrs.city.length < 2) {
return 'You must enter a real city.';
}
}
});
var user = new App.Models.User();
//user.on('change', function() {
// console.log('something changed'); - used for change anything
//});
user.on('invalid', function (model, invalid) {
console.log(invalid);
});
user.on('change:firstName', function() {
console.log('something changed');
});
user.set('firstName', '');
console.log(JSON.stringify(user));
console.log(user.get('birthday'));
})();
뭔가 : 결국
, 당신의 코드는 다음과 것인가? http://stackoverflow.com/questions/15614826/validate-method-inside-backbone-model-not-being-called/15615027#15615027 – nikoshr