天天看點

準備用EXTJS做一個項目,項目(一)準備階段:EXTJS 的CONFIGptype: treeviewdragdrop:This plugin provides drag and/or drop functionality for a TreeView。 今天對EXTJS的CONFIG用法有些迷惑,下面進行一下解讀:  

               打算使用EXTJS4.0作為工具。使用EXTJS提供的grid,tree,chart,form。首先準備學習一下TREE元件。項目必備元件。

ptype: treeviewdragdrop:This plugin provides drag and/or drop functionality for a TreeView。

今天對EXTJS的CONFIG用法有些迷惑,下面進行一下解讀:

Extjs 4中,為類型系統引入了Config概念,Config就是配置項的意思,用{configItem1:value1...}表示;

在對象構造的時候,會調用this.initConfig(config)将配置項初始化,每個配置項自動生成4個函數:get set reset apply。

Mixins也是新概念,相當于調用Ext.apply(this,other)将other類中的方法合并到目前的類中,也相當于另一種形式的繼承。

下面用代碼測試一下,使用了Siesta測試架構,有興趣可以google一下,很強大的測試系統。

Js代碼 

  1. StartTest(function(t) { 
  2. t.diag("Extjs common test"); 
  3. t.ok(Ext,"Ext is here"); 
  4. Ext.define("test.Talk", 
  5. talk:function() 
  6. return 'talk'
  7. ); 
  8. Ext.define("test.Person", 
  9. mixins: 
  10. everyOneNeedTalk:"test.Talk"
  11. }); 
  12. var p = Ext.create("test.Person"); 
  13. t.is('talk',p.talk(),'The method is mixin') 
  14. Ext.define("test.Student",{ 
  15. config:{ 
  16. gender:'boy'
  17. }, 
  18. constructor:function(config){ 
  19. this.initConfig(config); 
  20. //這裡需要調用initConfig,否則不會自動生成getter 和 setter 
  21. }); 
  22. var s = Ext.create('test.Student') 
  23. t.is(s.getGender(),'boy','generate getter') 
  24. s.setGender('girl'); 
  25. t.is(s.getGender(),'girl','generate setter') 
  26. t.done(); // Optional, marks the correct exit point from the test
  27. });

繼續閱讀