2011-04-19 110 views
19

我在Extjs4 librairie中遇到了一些問題。 我想使用treeEditor組件。Ext.loader未啓用缺少必填項?

Firebug的錯誤:

錯誤:未捕獲的異常:未啓用 Ext.Loader,所以 依賴性不能動態解析 。缺少必需的類: Ext.tree.TreeNode

我的代碼:

Ext.require([ 

'Ext.form.*', 
'Ext.grid.*', 
'Ext.tree.*', 
'Ext.data.*', 
'Ext.util.*', 
'Ext.loader.*', 
'Ext.state.*', 
'Ext.layout.container.Column', 
'Ext.tab.TabPanel' 

]); 

Ext.onReady(function(){ 

    // shorthand 
    Ext.QuickTips.init(); 


    var tree = Ext.create('Ext.tree.TreePanel', { 
      animate:false, 
      enableDD:false, 
    //  loader: new Tree.TreeLoader(), // Note: no dataurl, register a TreeLoader to make use of createNode() 
      lines: true, 
      rootVisible:false, 
     // selModel: new Ext.tree.MultiSelectionModel(), 
      containerScroll: false 
    }); 

     // set the root node 
     var root = Ext.create('Ext.tree.TreeNode',{ 
      text: 'Autos', 
      draggable:false, 
      id:'source' 
     }); 

     tree.on('contextmenu',showCtx); 
     tree.on('click',function(node,e){node.select();return false;}); 
     // json data describing the tree 

     var json = [ 
       {"text" : "1","allowEdit" : true, "id" : 300, "leaf" : false, "cls" : "folder", "children" : [ 
       {"text" : "11","allowEdit" : true, "id" : 3000, "leaf" : false, "cls" : "folder","children" :[ 
       {"text" : "111","allowEdit" : true, "id" : 300, "leaf" : false, "cls" : "folder","children" :[ 
       {"text" : "1111","allowEdit" : true, "id" : 300, "leaf" : true, "cls" : "file"}, 
       {"text" : "1112","allowEdit" : true, "id" : 300, "leaf" : true, "cls" : "file"}, 
       {"text" : "1113","allowEdit" : true, "id" : 300, "leaf" : true, "cls" : "file"} 
       ]}, 
       {"text" : "112","allowEdit" : true, "id" : 300, "leaf" : true, "cls" : "file"}, 
       {"text" : "113","allowEdit" : true, "id" : 300, "leaf" : true, "cls" : "file"} 
       ]}, 
       {"text" : "12","allowEdit" : true, "id" : 300, "leaf" : true, "cls" : "file"}, 
       {"text" : "13","allowEdit" : true, "id" : 300, "leaf" : true, "cls" : "file"} 
       ]}, 
       {"text" : "2","allowEdit" : true, "id" : 300, "leaf" : true, "cls" : "file"}, 
       {"text" : "3","allowEdit" : true, "id" : 300, "leaf" : true, "cls" : "file",iconCls:'node'} 
       ]; 

       for(var i = 0, len = json.length; i < len; i++) { 
       root.appendChild(tree.getLoader().createNode(json[i])); 
       } 

     var ge = Ext.create('Ext.tree.TreeEditor',tree,{},{ 
      allowBlank:false, 
      blankText:'Nom du dossier', 
      selectOnFocus:true, 
      cancelOnEsc:true, 
      completeOnEnter:true, 
      ignoreNoChange:true, 
      updateEl:true 
      }); 

      /*ge.on('beforestartedit', function(){ 

      if(!ge.editNode.attributes.allowEdit){ 
       return false; 
      } 
       });*/ 

     tree.setRootNode(root); 
     tree.render(); 
     root.expand(true); 

     }); 

謝謝:)

回答

50

的錯誤是由於不使裝載機。您可以通過啓用Ext.Loader:

Ext.Loader.setConfig({enabled:true}); 

您需要在onReady方法的開始調用此。

+0

它不工作了! 我有這個錯誤後: Erreur:未捕獲的異常:嘗試加載類'Ext.tree錯誤。TreeEditor'from path'./tree/TreeEditor.js':undefined – Mepps 2011-04-19 12:02:36

+0

新的錯誤是因爲Ext JS源代碼中沒有TreeEditor.js文件!我想你將不得不等待Sencha發佈它。 – 2011-04-19 12:07:52

+0

哦,好的..!我在sencha doc上看到TreeGrid! 非常感謝回答:) – Mepps 2011-04-19 12:10:18

2

這在ExtJs 4中適用於我。剛剛將Ext.Loader.setConfig({enabled:true});添加到了app.js的頂部。

1

真正的問題是,你正在使用EXT-debug.js,ext.js

改用:EXT-all.js或者EXT-dev.js

的閱讀動態加載

的index.html例如:

<html> 
    <head> 
     <title>Hello Ext</title> 
     <link rel="stylesheet" type="text/css" href="ext-4/resources/css/ext-all.css"> 
     <script type="text/javascript" src="ext-4/ext-dev.js"></script> 
     <script type="text/javascript" src="app.js"></script> 
    </head> 
    <body></body> 
</html> 

在你不需要啓用動態加載的例子,因爲動態加載其開發環境。 ext-all.js,ext.js用於部署。 ext-all-debug.js和ext-debug.js用於部署後的調試。

MVC和動態加載在部署中無用,因爲您必須有一個由sencha cmd(又名Sencha工具)生成的文件。

1

我看着這個,不得不退後一秒,因爲我是一個ExtJS新手。關於在OnReady調用之前放置它的通用聲明,我並不清楚。

對於版本5.0的Sencha API Docs網站上的以下內容還顯示此示例,以便充分了解調用Ext.Loader類的位置。儘管我認爲它有點誇大了多個JavaScript標籤。

<script type="text/javascript" src="ext-core-debug.js"></script> 
<script type="text/javascript"> 
    Ext.Loader.setConfig({ 
     enabled: true, 
     paths: { 
      'My': 'my_own_path' 
     } 
    }); 
</script> 
<script type="text/javascript"> 
    Ext.require(...); 

    Ext.onReady(function() { 
     // application code here 
    }); 
</script> 

我對自己的個人代碼所做的更改如下所示,並且它也可以正常工作。這非常簡單。

Ext.Loader.setConfig({enabled:true}); 

Ext.application({ 
    name    : 'MyApp', 
    appFolder   : 'app', 
    controllers   : [ 
     'MyApp.controller.item.Item' 
    ], 
    autoCreateViewport : true 

}); 

如果用裝載有問題,那麼你可能要檢討Ext.require和Ext.exclude類也獲得如何將這些交互加載自定義類,理解。