Backbone.js isValid模型通过使用validate()方法检查模型的状态。它检查每个属性的验证。
【backbone.js模型isvalid】句法:
model.isValid()
让我们举个例子。
请参阅以下示例:
<
!DOCTYPE html>
<
head>
<
title> isValid Example<
/title>
<
script src="http://img.readke.com/220416/03232222V-0.jpg" type="text/javascript"><
/script>
<
script src="http://img.readke.com/220416/032322B36-1.jpg" type="text/javascript"><
/script>
<
script src="http://img.readke.com/220416/032322O30-2.jpg" type="text/javascript"><
/script>
<
script type="text/javascript">
var Person = Backbone.Model.extend({
defaults: {
name: '', age: 25, }, validate: function(attributes) {
if (attributes.name == '') {
document.write("Please enter the name!!!!");
}
}
});
var person = new Person({
name: 'Sonoo'
});
document.write("The passed value for attribute 'name' is: ", person.isValid());
<
/script>
<
/head>
<
/html>
输出:
将以上代码保存在isvalid.html文件中,然后在新的浏览器中打开此文件。
文章图片
推荐阅读
- backbone.js模型url
- backbone.js模型validationerror
- backbone.js模型验证validate
- backbone.js模型tojson
- backbone.js模型destroy
- backbone.js模型save
- backbone.js模型fetch
- backbone.js模型sync
- backbone.js模型defaults