标签:mod ide hone a10 read efi bee end ready
1.创建Model
a.Ext.create继承的方式
1 Ext.define(‘Student‘,{ 2 3 extend: ‘Ext.data.Model‘, 4 5 fields:[{name:‘name‘,type:‘string‘}] 6 7 });
b.Ext.regModel的方式
1 Ext.regModel("Student",{ 2 3 fields:[{name:‘name‘,type:‘string‘}] 4 }); (浏览器下提示 Ext.regModel has been deprecated.) 5 6 推荐使用第一种
2.验证
a.官方的例子
1 Ext.onReady(function(){ 2 Ext.define(‘User‘, { 3 extend: ‘Ext.data.Model‘, 4 fields: [ 5 { name: ‘name‘, type: ‘string‘ }, 6 { name: ‘age‘, type: ‘int‘ }, 7 { name: ‘phone‘, type: ‘string‘ }, 8 { name: ‘gender‘, type: ‘string‘ }, 9 { name: ‘username‘, type: ‘string‘ }, 10 { name: ‘alive‘, type: ‘boolean‘, defaultValue: true } 11 ], 12 //Ext.data.validations类 13 validators:[ 14 {type: ‘presence‘, field: ‘age‘}, 15 {type: ‘length‘, field: ‘name‘, min: 2}, 16 {type: ‘inclusion‘, field: ‘gender‘, list: [‘Male‘, ‘Female‘]}, 17 {type: ‘exclusion‘, field: ‘username‘, list: [‘Admin‘, ‘Operator‘]}, 18 {type: ‘format‘, field: ‘username‘, matcher: /([a-z]+)[0-9]{2,3}/} 19 ] 20 }); 21 22 var instance = Ext.create(‘User‘, { 23 name: ‘3‘, 24 gender: ‘Male‘, 25 username: ‘edspencer‘ 26 }); 27 //返回Ext.data.Errors类 28 var validation = instance.validate(); 29 console.log(validation); 30 });
b.一对多与多对一
c.自定义验证
标签:mod ide hone a10 read efi bee end ready
原文地址:https://www.cnblogs.com/fzsyw/p/5681490.html