jQuery(document).ready(function($) {
var FirstModel = Backbone.Model.extend({
initialize: function() {
this.validate();
},
validate: function(attributes) {
if(attributes && attributes.age < 1) {
return "Age must be negative.";
}
}
});
fmodel = new FirstModel({
});
fmodel.set({
name: "Tuong",
team: "Solution",
age: 0
});
var ModelView = Backbone.View.extend({
model: fmodel,
initialize: function() {
this.render();
},
render: function() {
console.log(this.model.toJSON());
}
});
vmodel = new ModelView();
});
jQuery(document).ready(function($) {
var FirstModel = Backbone.Model.extend({
initialize: function() {
this.validate();
},
validate: function(attributes) {
if(attributes && attributes.age < 1) {
return "Age must be negative.";
}
}
});
fmodel = new FirstModel({
});
fmodel.set({
name: "Tuong",
team: "Solution",
age: 0
});
var ModelView = Backbone.View.extend({
model: fmodel,
initialize: function() {
this.render();
},
render: function() {
if(this.model.isValid()) {
console.log("Valid values are false");
}else {
console.log(this.model.validationError);
}
console.log(this.model.toJSON());
}
});
vmodel = new ModelView();
});