extJs数据模型之Model博客分类:
1 model的创建
- //我们利用Ext.define来创建我们的模型类
- //DB table person(name,age,email)
- Ext.define("person",{
- extend:"Ext.data.Model",
- fields:[
- {name:'name',type:'auto'},
- {name:'age',type:'int'},
- {name:'email',type:'auto'}
- ]
- });
- //我们利用Ext.regModel来创建我们的模型类
- //mvc模式中model一定是m层
- Ext.regModel("user",{
- fields:[
- {name:'name',type:'auto'},
- {name:'age',type:'int'},
- {name:'email',type:'auto'}
- ]
- });
//我们利用Ext.define来创建我们的模型类
//DB table person(name,age,email)
Ext.define("person",{
extend:"Ext.data.Model",
fields:[
{name:'name',type:'auto'},
{name:'age',type:'int'},
{name:'email',type:'auto'}
]
}); //我们利用Ext.regModel来创建我们的模型类
//mvc模式中model一定是m层
Ext.regModel("user",{
fields:[
{name:'name',type:'auto'},
{name:'age',type:'int'},
{name:'email',type:'auto'}
]
});
2 创建model的实例以及实例化对象的方法
- //实例化我们的person(一下是3种方法)
- //1 new关键字
- var p = new person({
- name:'baomengjie',
- age:23,
- email:'bmjlovejava@126.com'
- });
- //alert(p.get());
- //2 Ext.create (官方推荐)
- var p1 = Ext.create("person",{
- name:'baomengjie',
- age:23,
- email:'bmjlovejava@126.com'
- });
- //alert(p1.get('age'));
- //3 Ext.ModelMgr.create
- var p2 = Ext.ModelMgr.create({
- name:'baomengjie',
- age:23,
- email:'bmjlovejava@126.com'
- },"user");
- alert(p2.get('email'));