ExtJs Data Model Model

1. Create a Model

a.Ext.create way of inheritance

1 Ext.define('Student',{
2 
3     extend: 'Ext.data.Model',  
4 
5     fields:[{name:'name',type:'string'}]
6 
7   });
View Code

b.Ext.regModel way

. 1 Ext.regModel ( "Student" , {
 2  
. 3      Fields: [{name: 'name', type: 'String' }]
 . 4    }); (. Tips Ext.regModel has been deprecated the browser)
 . 5  
. 6 is recommended The first
View Code

2. Verify

a official of examples.

 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     });
View Code

b. and many-to-many

c. custom authentication

Guess you like

Origin www.cnblogs.com/fzsyw/p/5681490.html