extjs 4 tree select a specific node by its internal id (not by record index)

假如想象 提交于 2019-12-07 04:57:24

问题


I'm trying to sync a dataview (explorer window) with a tree (directory tree). When I click on an element on my dataview, I'd like the same node gets selected on the tree

The problem is that using the tree.getSelectionModel().select(index) doesn't allow me to select the node by its internal id (the id I provided in my treestore), but only by the record index... So I just can't sync both views... There would be the solution of the expandPath(), but my treestore is fed by a relational database (id,name,parent_id etc..), so finding the full path is(or could be) a heavy load for the server (I'd like to avoid to have to provide any path...).

Basically I would like to be able to say "expand the node where the "id= " (or any other key/value of the treestore).

Is it possible ? Is there any workaround ?

Thank you for reading me !


回答1:


The tree.getSelectionModel().select(record) function can accept a record instance instead of an index. I would do something like this:

var record = tree.getRootNode().findChild('id_name','record_id',true);
tree.getSelectionModel().select(record);

for more info on the findChild function, check out the NodeInterface docs here: http://docs.sencha.com/ext-js/4-0/#/api/Ext.data.NodeInterface-method-findChild




回答2:


you can also use selecteditemtree.data.id for this.



来源:https://stackoverflow.com/questions/6373671/extjs-4-tree-select-a-specific-node-by-its-internal-id-not-by-record-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!