Ext 4ノート
1、クラスの2の定義と3のインスタンス化方式
2、カスタムクラス、イベントメカニズム
3、通常のjavascript定義クラスとアクセス権限
- Ext.onReady(function() {
- // 2
- Ext.define("person",{
- extend : "Ext.data.Model",
- fields:[
- {name:'name',type:'auto'},
- {name:'age',type:'int'},
- {name:'email',type:'auto'}
- ]
- });
-
- Ext.regModel("user",{
- fields:[
- {name:'name',type:'auto'},
- {name:'age',type:'int'},
- {name:'email',type:'auto'}
- ]
- });
-
- //instance
- //method 1
- var p1 = new persion({
- name : 'zhangsan',
- age : 12,
- email : '[email protected]'
- });
- alert(p1.get('name'));
- //method 2
-
- var p2 = Ext.create("persion",{
- name : 'zhangsan',
- age : 12,
- email : '[email protected]'
- });
- alert(p2.get('name'));
-
- //method 3
- var p3 = Ext.ModelMgr.create({
- name : 'zhangsan',
- age : 12,
- email : '[email protected]'
- });
- alert(p3.get('email'));
- });
2、カスタムクラス、イベントメカニズム
- Ext.onReady({
- Ext.define("children",{
- extend : 'Ext.util.Observable',
- constructor : function(){
- this.state = "hungry",
- this.setMilk = function(milk){
- this.fireEvent('hungry',milk);
- },
- this.addEvents('hungry':true),
- this.addListener('hungry',function(milk){
- if(this.state == 'hungry'){
- this.drink(milk);
- }else{
- Ext.Msg.alert("no hungry");
- }
- }),
- this.drink = function(milk){
- alert("eat one bottle of milk.");
- }
-
-
- }
- });
-
- var children = Ext.create("children",{});
- children.setMilk(" ");
- });
3、通常のjavascript定義クラスとアクセス権限
- function user() {
- //public
- this.name = 'uspcat';
- this.age = 20;
- //private
- var email = "[email protected]";
- // private
- this.getEmail = function() {
- return email;
- }
- }
- var u = new user();
- alert(u.name);
- alert(u.age);
- alert(u.getEmail());