2012-02-09 19 views
1

我想使用Ext.data.NodeInterface類的insertBefore方法在ExtJS 4.0.2中向樹添加新節點。Ext.data.NodeInterface insertBefore不是函數

但我仍然得到錯誤:「的insertBefore是不是一個函數」

var config = { 
    allowDrag: false, 
    allowDrop: false, 
    cls: 'myClass', 
    iconCls: 'myIconClass', 
    leaf: true, 
    text: 'someText' 
}; 
var node1 = Ext.create('Ext.data.NodeInterface', config); 
var node2 = Ext.create('Ext.data.NodeInterface', config); 
var node3 = null; 

node1.insertBefore(node2, node3); // "node1.insertBefore is not a function" 

任何想法可能是錯誤的?

回答

1

來自文檔:In general this class will not be used directly by the developer.當您檢查node1時,您會注意到它實際上並沒有此功能。

我想你可能實際上需要使用Ext.data.NodeInterface.createNode()函數來創建應用此接口的Ext.data.Record的實例。

+0

是的,Ext.data.NodeInterface.createNode()幫助。現在我正在使用它:
var node1 = treeStore.getRootNode(); var node2 = node1.createNode(config); var node3 = null; node1.insertBefore(node2,node3); 它工作正常。非常感謝你。 – Bammal 2012-02-09 16:40:33