[02]EXTJS4.0의 새로운 기능

노트:
1. JS 클래스 선언 및 객체 작성
2. 원형 방법은 EXTJS로 윈도우를 만듭니다
3. 버튼 하나로 윈도우 창을 터치하여 EXTJS의 이벤트 메커니즘을 알아보기
4. EXTJS4.0의 create로 window 만들기
5. define 사용자 정의 클래스를 이용하여 (extend) window 계승
//초기화 방법 구조기
   initComponent:function(){
this.callParent(arguments);
   }
6.requires JS의 비동기 로드
7.config 자동 get 및 set
8.mixins류의 혼합
 
 
--------------------------------------------------------------------------------- 
이 예는 주로 유형의 사유 속성과 공유 속성을 말한다
lesson02.html

  
  
  
  
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
  2. <html> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
  5. <title>HELLO WORD</title> 
  6. <link rel="stylesheet" type="text/css" href="../extjs-4.1.0/resources/css/ext-all.css"/> 
  7. <script type="text/javascript" src="../extjs-4.1.0/bootstrap.js"></script> 
  8. <script type="text/javascript" src="indexDemo.js"></script> 
  9. </head> 
  10. <body> 
  11. </body> 
  12. </html> 

indexDemo.js

  
  
  
  
  1. // function 
  2. function user(){ 
  3.   //java  public 
  4.   this.Name = 'uspcat'
  5.   this.age = 26; 
  6.  
  7.   //var  private 
  8.   var email = "[email protected]";   
  9.  
  10.    
  11.   this.getEmail = function(){ 
  12.     return email; 
  13.   } 
  14.  
  15. var u = new user(); 
  16. alert(u.Name); 
  17. alert(u.email); 
  18. alert(u.getEmail()); 
  19.  
  20. var person = { 
  21.     name:'yfc'
  22.     age:26 
  23. }; 
  24. alert(person.name + " " + person['age']); 

------------------------------------------------
이 예는 주로 Ext.window를 만드는 방법을 말한다.윈도, show 방법으로 창을 표시할 수 있습니다.
lesson02.html

  
  
  
  
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
  2. <html> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
  5. <title>Ext.window.Window</title> 
  6. <link rel="stylesheet" type="text/css" href="../extjs-4.1.0/resources/css/ext-all.css"/> 
  7. <script type="text/javascript" src="../extjs-4.1.0/bootstrap.js"></script> 
  8. <script type="text/javascript" src="indexDemo2.js"></script> 
  9. </head> 
  10. <body> 
  11. </body> 
  12. </html> 

indexDemo2.js

  
  
  
  
  1. (function(){ 
  2.     Ext.onReady(function(){ 
  3.         var win = new Ext.window.Window({ 
  4.                 width:400, 
  5.                     height:300, 
  6.                     title:'uspcat'  
  7.                    }); 
  8.         win.show(); 
  9.  
  10.     }); 
  11. })(); 

------------------------------------------------------------------
이 예는 주로 Extjs가 Ext.get (지정한 id를 가져오는 페이지 요소) 과 이벤트를 어떻게 사용하는지 보여 줍니다.
lesson02_02.html

  
  
  
  
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
  2. <html> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
  5. <title>Ext.window.Window</title> 
  6. <link rel="stylesheet" type="text/css" href="../extjs-4.1.0/resources/css/ext-all.css"/> 
  7. <script type="text/javascript" src="../extjs-4.1.0/bootstrap.js"></script> 
  8. <script type="text/javascript" src="indexDemo2.js"></script> 
  9. </head> 
  10. <body> 
  11.   <button id="myb">Show</button> 
  12. </body> 
  13. </html> 

indexDemo3.js

  
  
  
  
  1. (function(){ 
  2.     Ext.onReady(function(){ 
  3.          var win = new Ext.window.Window({ 
  4.             width:400, 
  5.             height:300, 
  6.             title:'uspcat', 
  7.             closeAction:false// , win.show() el is null    el.addCls.apply(el,  
  8.  
  9. arguments); 
  10.          }); 
  11.     //1. dom  
  12.         //2.  
  13.         //3. win show  
  14.         Ext.get("myb").on("click",function(){ 
  15.       win.show(); 
  16.         },this); 
  17.     }); 
  18. })(); 

----------------------------------------------------------------------------------
이 예는 주로 Ext.Function을 말한다.alias 대상 만드는 방법의 별명
lesson02_03.html

  
  
  
  
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
  2. <html> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
  5. <title> </title> 
  6. <link rel="stylesheet" type="text/css" href="../extjs-4.1.0/resources/css/ext-all.css"/> 
  7. <script type="text/javascript" src="../extjs-4.1.0/bootstrap.js"></script> 
  8. <script type="text/javascript" src="indexDemo4.js"></script> 
  9. </head> 
  10. <body> 
  11. </body> 
  12. </html> 

indexDemo4.js

  
  
  
  
  1. (function(){ 
  2.     Ext.onReady(function(){ 
  3.     var o = { 
  4.       say : function(){ 
  5.         alert(111); 
  6.       } 
  7.         } 
  8.        var fn = Ext.Function.alias(o,'say'); 
  9.        fn(); 
  10.     }); 
  11. })(); 

------------------------------------------------------------------------------
이 예에서는 주로 Ext.create를 사용하여 객체를 만드는 방법을 보여 줍니다.
lesson02_04.html

  
  
  
  
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
  2. <html> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
  5. <title>Ext.create</title> 
  6. <link rel="stylesheet" type="text/css" href="../extjs-4.1.0/resources/css/ext-all.css"/> 
  7. <script type="text/javascript" src="../extjs-4.1.0/bootstrap.js"></script> 
  8. <script type="text/javascript" src="indexDemo5.js"></script> 
  9. </head> 
  10. <body> 
  11. </body> 
  12. </html> 

indexDemo5.js

  
  
  
  
  1. (function(){ 
  2.     Ext.onReady(function(){ 
  3.     var win = Ext.create('Ext.window.Window',{ 
  4.       width:400, 
  5.           height:300, 
  6.           title:'uspcat' 
  7.         }); 
  8.         win.show(); 
  9.     }); 
  10. })(); 

--------------------------------------------------------------
이 예는 주로 Ext.define 방법과 initComponent 속성을 말한다. initComponent는 클래스의 대상을 만들 때 가장 자동으로 호출되고 자바의 구조기와 맞먹는다. 또한callParent 방법도 언급했다.
lesson02_06.html

  
  
  
  
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
  2. <html> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
  5. <title>Ext.create</title> 
  6. <link rel="stylesheet" type="text/css" href="../extjs-4.1.0/resources/css/ext-all.css"/> 
  7. <script type="text/javascript" src="../extjs-4.1.0/bootstrap.js"></script> 
  8. <script type="text/javascript" src="indexDemo6.js"></script> 
  9. </head> 
  10. <body> 
  11. </body> 
  12. </html> 

indexDemo6.js

  
  
  
  
  1. (function(){ 
  2.     Ext.onReady(function(){ 
  3.     Ext.define("myWin",{ 
  4.       extend:'Ext.window.Window'
  5.           width:400, 
  6.           height:300, 
  7.           title:'uspcat'
  8.           newtitle:'new uspcat'
  9.           mySetTitle:function(){ 
  10.             this.title = this.newtitle; 
  11.           }, 
  12.       initComponent: function(){ 
  13.             this.mySetTitle(); 
  14.         this.callParent(arguments); 
  15.       } 
  16.     }); 
  17.         Ext.create('myWin',{ 
  18.       title:'my win' 
  19.     }).show(); 
  20.     }); 
  21. })(); 

initComponent 메서드는 자동으로 호출됩니다.
----------------------------------------------------------------------------------
이 예는 주로 js 파일을 어떻게 도입하는지 강의한다
ux\mywin.js

  
  
  
  
  1. Ext.define("myWin",{ 
  2.       extend:'Ext.window.Window'
  3.           width:400, 
  4.           height:300, 
  5.           title:'uspcat'
  6.           newtitle:'new uspcat'
  7.           mySetTitle:function(){ 
  8.             this.title = this.newtitle; 
  9.           }, 
  10.       initComponent: function(){ 
  11.             this.mySetTitle(); 
  12.         this.callParent(arguments); 
  13.       } 
  14.     }); 

lesson02_06.html

  
  
  
  
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
  2. <html> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
  5. <title>Ext.create</title> 
  6. <link rel="stylesheet" type="text/css" href="../extjs-4.1.0/resources/css/ext-all.css"/> 
  7. <script type="text/javascript" src="../extjs-4.1.0/bootstrap.js"></script> 
  8. <script type="text/javascript" src="indexDemo6.js"></script> 
  9. <script type="text/javascript" src="ux/mywin.js"></script> 
  10. </head> 
  11. <body> 
  12. </body> 
  13. </html> 

indexDemo6.js

  
  
  
  
  1. (function(){ 
  2.     Ext.onReady(function(){ 
  3.         Ext.create('myWin',{ 
  4.       title:'my win' 
  5.     }).show(); 
  6.     }); 
  7. })(); 

--------------------------------------------------------------------------------------
이 예는 서버를 부팅해야 정상적으로 작동할 수 있으며 두 가지 주의가 필요합니다.
첫 번째는요.

  
  
  
  
  1. Ext.Loader.setConfig({  
  2.  enabled:true,  
  3.  paths:{  
  4.    myApp:'lessonTwo/ux'//   
  5.  }  
  6. );  

다른 하나는 클래스 이름입니다. 현재 폴더 아래의 파일 아래에 있는 js 파일이어야만 동적 불러올 수 있습니다. 클래스 이름은 현재 폴더 아래의 파일 이름과 js 파일 이름이어야 합니다.
indexDemo7.js

  
  
  
  
  1. (function(){ 
  2.    Ext.Loader.setConfig({ 
  3.      enabled:true
  4.      paths:{ 
  5.        myApp:'lessonTwo/ux'//  
  6.      } 
  7.    }); 
  8.  
  9.    Ext.onReady(function(){ 
  10.        Ext.create('ux.myWin2',{// ux/myWin2 ux.myWin2  
  11.   title:'my win'
  12.          //requires:['myWin'] 
  13. }).show(); 
  14.    }); 
  15. )(); 

lesson02_07.html

  
  
  
  
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
  2. <html> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
  5. <title>Ext.create</title> 
  6. <link rel="stylesheet" type="text/css" href="../extjs-4.1.0/resources/css/ext-all.css"/> 
  7. <script type="text/javascript" src="../extjs-4.1.0/bootstrap.js"></script> 
  8. <script type="text/javascript" src="indexDemo7.js"></script> 
  9. </head> 
  10. <body> 
  11. </body> 
  12. </html> 

ux\myWin2.js

  
  
  
  
  1. Ext.define("ux.myWin2",{ 
  2.       extend:'Ext.window.Window'
  3.           width:400, 
  4.           height:300, 
  5.           title:'uspcat'
  6.           newtitle:'new uspcat'
  7.           mySetTitle:function(){ 
  8.             this.title = this.newtitle; 
  9.           }, 
  10.       initComponent: function(){ 
  11.             this.mySetTitle(); 
  12.         this.callParent(arguments); 
  13.       } 
  14.     }); 

----------------------------------------------------------------------------------
이 예는 주로 버튼을 누르면 my Win2를 보여 줍니다.js 이 js 파일은 동적 불러오기입니다
lesson02_08.html

  
  
  
  
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
  2. <html> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
  5. <title>Ext.create</title> 
  6. <link rel="stylesheet" type="text/css" href="../extjs-4.1.0/resources/css/ext-all.css"/> 
  7. <script type="text/javascript" src="../extjs-4.1.0/bootstrap.js"></script> 
  8. <script type="text/javascript" src="indexDemo8.js"></script> 
  9. </head> 
  10. <body> 
  11.   <button id="myb">Show</button> 
  12. </body> 
  13. </html> 

indexDemo8.js

  
  
  
  
  1. (function(){ 
  2.    Ext.Loader.setConfig({ 
  3.      enabled:true
  4.      paths:{ 
  5.        myApp:'lessonTwo/ux'//  
  6.      } 
  7.    }); 
  8.  
  9.    Ext.onReady(function(){ 
  10.        Ext.get("myb").on("click",function(){ 
  11.          Ext.create('ux.myWin2',{// ux/myWin2 ux.myWin2  
  12.     title:'my win'
  13.            //requires:['myWin'] 
  14.   }).show();         
  15. }); 
  16.  
  17.    }); 
  18. )(); 

ux\myWin2.js

  
  
  
  
  1. Ext.define("ux.myWin2",{ 
  2.       extend:'Ext.window.Window'
  3.           width:400, 
  4.           height:300, 
  5.           title:'uspcat'
  6.           newtitle:'new uspcat'
  7.           mySetTitle:function(){ 
  8.             this.title = this.newtitle; 
  9.           }, 
  10.       initComponent: function(){ 
  11.             this.mySetTitle(); 
  12.         this.callParent(arguments); 
  13.       } 
  14.     }); 

-------------------------------------------------------------------------------------
이 예는 주로 Ext.define에서config 속성을 말하는데, 설정하면 getPropertyName 방법이 자동으로 나타납니다
lesson02_09.html

  
  
  
  
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
  2. <html> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
  5. <title>Ext.create</title> 
  6. <link rel="stylesheet" type="text/css" href="../extjs-4.1.0/resources/css/ext-all.css"/> 
  7. <script type="text/javascript" src="../extjs-4.1.0/bootstrap.js"></script> 
  8. <script type="text/javascript" src="indexDemo9.js"></script> 
  9. </head> 
  10. <body> 
  11.   <button id="myb">Show</button> 
  12. </body> 
  13. </html> 

indexDemo9.js

  
  
  
  
  1. (function(){ 
  2.    Ext.Loader.setConfig({ 
  3.      enabled:true
  4.      paths:{ 
  5.        myApp:'lessonTwo/ux'//  
  6.      } 
  7.    }); 
  8.    Ext.onReady(function(){ 
  9.  
  10.        Ext.get("myb").on("click",function(){ 
  11.          var win = Ext.create('ux.myWin3',{// ux/myWin2 ux.myWin2  
  12.     title:'my win'
  13.            price:60 
  14.   });    
  15.          alert(win.getPrice()); 
  16.          win.show();     
  17. }); 
  18.  
  19.    }); 
  20. )(); 

ux\myWin3.js

  
  
  
  
  1. Ext.define("ux.myWin3",{ 
  2.       extend:'Ext.window.Window'
  3.           width:400, 
  4.           height:300, 
  5.           config:{ 
  6.               price:500 
  7.           }, 
  8.           title:'uspcat'
  9.           newtitle:'new uspcat'
  10.           mySetTitle:function(){ 
  11.             this.title = this.newtitle; 
  12.           }, 
  13.       initComponent: function(){ 
  14.             this.mySetTitle(); 
  15.         this.callParent(arguments); 
  16.       } 
  17.     }); 

----------------------------------------------------------------------------------
마지막 예는 주로 Ext.define의mixins 속성을 말하는데 사실 js의 실례 계승법과 매우 유사하다
lesson02_10.html

  
  
  
  
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
  2. <html> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
  5. <title>Ext.create</title> 
  6. <link rel="stylesheet" type="text/css" href="../extjs-4.1.0/resources/css/ext-all.css"/> 
  7. <script type="text/javascript" src="../extjs-4.1.0/bootstrap.js"></script> 
  8. <script type="text/javascript" src="indexDemo10.js"></script> 
  9. </head> 
  10. <body> 
  11. </body> 
  12. </html> 

indexDemo10.js

  
  
  
  
  1.  (function(){ 
  2.     Ext.onReady(function(){ 
  3.     Ext.define('say',{ 
  4.       cansay:function(){ 
  5.          alert("hello"); 
  6.       } 
  7.     }); 
  8.  
  9.     Ext.define('sing',{ 
  10.       sing:function(){ 
  11.              alert('sing hello 123'); 
  12.       } 
  13.     }); 
  14.  
  15.     Ext.define('user',{ 
  16.           extend:'sing',//  
  17.       mixins:{ 
  18.             say:'say'// say say  
  19.       } 
  20.     }); 
  21.         var u = Ext.create('user',{}); 
  22.         u.cansay(); 
  23.         u.sing(); 
  24.     }); 
  25. })(); 

11

좋은 웹페이지 즐겨찾기