2011-09-27 70 views
0

我正在使用樹編輯器。我只需要雙擊樹節點就可以編輯。到目前爲止,我已經做到了這一點Extjs樹編輯器 - 禁用單擊即可編輯

var tree = new Ext.tree.TreePanel({ 
     root: this.getChildren(), 
     height: 300, 
     loader: new Ext.tree.TreeLoader(), 
     useArrows: true, 
     autoScroll: true, 
     listeners: { 
      dblclick: onTreeNodeDblClick 
     } 
    }); 

    var treeEditor = new Ext.tree.TreeEditor(tree, {}, { 
     cancelOnEsc: true, 
     completeOnEnter: true, 
     selectOnFocus: true, 
     allowBlank: false, 
     listeners: { 
      complete: onTreeEditComplete 
     } 
    }); 

    onTreeNodeDblClick: function (n) { 
     treeEditor.editNode = n; 
     treeEditor.startEdit(n.ui.textNode); 
    } 

    onTreeEditComplete: function (treeEditor, o, n) {} 

我已經找遍了API找到類似「clicksToEdit」這是我們在編輯器網格使用,但不能發現任何東西。有沒有辦法做到這一點?

回答

0

從Ext.tree.TreePanel的API:

beforeclick : (Node node, Ext.EventObject e)

Fires before click processing on a node. Return false to cancel the default action.

所以,你可以這樣做:

var tree = new Ext.tree.TreePanel({ 
    root: this.getChildren(), 
    height: 300, 
    loader: new Ext.tree.TreeLoader(), 
    useArrows: true, 
    autoScroll: true, 
    listeners: { 
     dblclick: onTreeNodeDblClick, 
     beforeclick: function() { return false;} 
    } 

});

2

Ext.tree.TreeEditor增加了兩個事件偵聽器(beforeclick,DBLCLICK),以樹 所以你可能會取消其從樹上

tree.on('afterrender', function() { 
    tree.un('beforeclick', treeEditor.beforeNodeClick, treeEditor); 
    tree.un('dblclick', treeEditor.onNodeDblClick, treeEditor); 
}) 
+0

幫助了我。謝謝! – blogofsongs