ExtJS - 获取项目的完整路径

时间:2013-10-15 15:48:56

标签: javascript extjs extjs4 extjs4.1 extjs4.2

我有Ext.data.TreeStore。我使用Ext.data.TreeStore。 每个节点都有unicue ID

我需要这样的东西:当我选择节点时,我需要提醒它的完整路径(我的意思是:我的节点id,它的parrent id,它的parrent id和root id)。

例如,如果我点击 childOf(2childOf(Root))我需要[root,2childOf(Root),childOf(2childOf(Root))的ID

 ROOT
    1childOf(Root)
    2childOf(Root)
                  childOf(2childOf(Root))

我该怎么做?

1 个答案:

答案 0 :(得分:3)

NodeInterface getPath(),可能就是你想要的

getPath( [field], [separator] ) : String
Gets the hierarchical path from the root of the current node.

Available since: 4.0.4

Parameters
field : String (optional)
The field to construct the path from. Defaults to the model idProperty.
separator : String (optional)
A separator to use.

Defaults to: "/"
Returns
String
The node path

这里是small sample

Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
width: 200,
height: 150,
store: store,
rootVisible: false,
listeners: {
    itemdblclick: function( panel, record, item, index, e, eOpts) {
        alert(record.getPath('text','/'));
    }
},
renderTo: Ext.getBody()

});