2012-12-03 65 views
0

我試圖顯示一個extjs-4樹,後臺存儲是從ajax調用(這看起來是成功的),但沒有填充json顯示。相反,我得到一個錯誤:Javascript(ExtJS 4.1.1)TypeError:t爲空

TypeError: t is null ext-all.js (line 38) 

編輯: TypeError: el is null在該行:

el = el.dom || Ext.getDom(el);


線現在,我使用ext-dev.js這給錯誤 38除了我想知道我是否在我的javascript中做出任何明顯的錯誤...

Ext.require([ 
    'Ext.tree.*', 
    'Ext.data.*' 
]); 

Ext.onReady(function() { 

    Ext.define('pools', { 
     extend: 'Ext.data.Model', 
     fields: ['text', 'id'] 
    }); 

    var store = Ext.create('Ext.data.TreeStore', { 
     autoLoad: true, 
     model: 'pools', 
     proxy: { 
      type: 'ajax', 
      url: 'get_all', 
      reader: 'json' 
     } 
    }); 

    store.load(); 

    // create the Tree 
    var tree = Ext.create('Ext.tree.Panel', { 
     store: store, 
     rootVisible: false, 
     viewConfig: { 
      plugins: [{ 
       ptype: 'treeviewdragdrop' 
      }] 
     }, 
     height: 350, 
     width: 400, 
     title: 'Directory Listing', 
     renderTo: 'viewer', 
     collapsible: true 
    }); 
}); 

,成功地返回JSON對象是:

{"text": ".", "children": [{"text": "pool1", "id": "pool1", "children": [{"text": "pool1/vol01", "leaf": "true", "id": "pool1/vol01"}]}, {"text": "pool5", "id": "pool5", "children": [{"text": "pool5/vol", "leaf": "true", "id": "pool5/vol"}, {"text": "pool5/vol2", "leaf": "true", "id": "pool5/vol2"}]}]} 

使用谷歌瀏覽器堆棧跟蹤顯示:

Uncaught TypeError: Cannot read property 'dom' of null ext-dev.js:20437 
Ext.define.doInsert ext-dev.js:20437 
Ext.define.append ext-dev.js:17115 
Ext.define.render Renderable.js:783 
Ext.define.constructor AbstractComponent.js:1126 
Base.implement.callParent ext-dev.js:6271 
Ext.define.constructor Component.js:336 
Base.implement.callParent ext-dev.js:6271 
Ext.define.constructor Panel.js:144 
constructor ext-dev.js:7459 
(anonymous function) 
Ext.ClassManager.instantiate ext-dev.js:8199 
(anonymous function) ext-dev.js:3015 
(anonymous function) viewer.js:26 <----------- from my javascript above (var tree=...) 
(anonymous function) ext-dev.js:14498 
Ext.util.Event.Ext.extend.fire ext-dev.js:14658 
Ext.apply.readyEvent.event.fire ext-dev.js:14901 
Ext.apply.fireReadyEvent ext-dev.js:14999 
Ext.apply.onDocumentReady ext-dev.js:15023 
fn ext-dev.js:10056 
Ext.apply.triggerReady ext-dev.js:10042 
Ext.apply.refreshQueue ext-dev.js:9540 
Ext.apply.refreshQueue ext-dev.js:9541 
Ext.apply.refreshQueue ext-dev.js:9541 
Ext.apply.refreshQueue ext-dev.js:9541 
Ext.apply.refreshQueue ext-dev.js:9541 
Ext.apply.onFileLoaded ext-dev.js:9947 
(anonymous function) ext-dev.js:3001 
onLoadFn 

我該如何解決這個問題?

+1

當你使用'EXT-dev.js',而不是'EXT-all.js'會發生什麼?海事組織你應該使用前者,而不是後者,在這個階段發現問題。 –

+0

'TypeError:el is null' at'el = el.dom || Ext.getDom(el);' – Awalias

+0

發現錯誤! div id在.js和.html之間有不同的名稱。 DOH! – Awalias

回答

2

下面添加HTML代碼正文頁面的:

<div id="viewer"></div> 
+0

這實際上證明是我的問題!我在div id中犯了一個錯字!然而,我真正的錯在於使用'ext-all.js'進行開發 – Awalias

相關問題