码迷,mamicode.com
首页 > 其他好文 > 详细

model 的验证

时间:2014-11-17 19:07:49      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   ar   sp   div   on   log   

 1 Ext.onReady(function(){
 2              Ext.define(‘User‘, {  
 3                 extend: ‘Ext.data.Model‘,  
 4                 fields: [  
 5                     { name: ‘name‘, type: ‘string‘ },  
 6                     { name: ‘gender‘, type: ‘string‘},
 7                     { name: ‘username‘, type: ‘string‘ },
 8                     { name: ‘f‘, type: ‘string‘}, 
 9                 ],  
10               
11                 validators:{  
12                     //判断id不得大于1位,
13                     //age: { type: ‘presence‘},
14                     name: { type: ‘length‘, min: 2, max: 5},
15                     gender: { type: ‘inclusion‘, list: [‘Male‘, ‘Female‘] }, 
16                     username: { type: ‘exclusion‘, list: [‘Admin‘, ‘Operator‘] },
17                     f: function(value){ alert(value);  },  //自定义方法判断
18                 }
19             });  
20 
21             var instance = Ext.create(‘User‘, { 
22                 name: ‘1‘, 
23                 gender: ‘Male‘,
24                 username: ‘not Admin‘,
25                 f: ‘hello‘,
26             });   
27               
28             var validation = instance.getValidation();  
29             //验证成功返回false 验证失败返回true
30             alert(validation.isValid());  //判断验证是否正确
31             console.log(validation);
32         });

 

model 的验证

标签:style   blog   io   color   ar   sp   div   on   log   

原文地址:http://www.cnblogs.com/shaoshao/p/4103958.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!