打算使用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代碼
- StartTest(function(t) {
- t.diag("Extjs common test");
- t.ok(Ext,"Ext is here");
- Ext.define("test.Talk",
- {
- talk:function()
- {
- return 'talk'
- }
- }
- );
- Ext.define("test.Person",
- {
- mixins:
- {
- everyOneNeedTalk:"test.Talk"
- }
- });
- var p = Ext.create("test.Person");
- t.is('talk',p.talk(),'The method is mixin')
- Ext.define("test.Student",{
- config:{
- gender:'boy'
- },
- constructor:function(config){
- this.initConfig(config);
- //這裡需要調用initConfig,否則不會自動生成getter 和 setter
- }
- });
- var s = Ext.create('test.Student')
- t.is(s.getGender(),'boy','generate getter')
- s.setGender('girl');
- t.is(s.getGender(),'girl','generate setter')
- t.done(); // Optional, marks the correct exit point from the test
- });