gpt4 book ai didi

javascript - 如何在 extJs 4.1 树面板中突出显示节点

转载 作者:行者123 更新时间:2023-12-02 18:25:40 24 4
gpt4 key购买 nike

我有一个 ExtJs 4.1 树面板。该树有多个节点。现在我允许用户在树节点上执行包含搜索。因此,如果我对单词 ASP.NET 运行搜索,搜索应突出显示文本中包含关键字 ASP.NET

的所有节点

我怎样才能做到这一点?

谢谢

最佳答案

您需要从 TreePanel 搜索子项的根节点,然后使用 RegEx 测试该节点的值与搜索文本的值。

工作示例

var store = Ext.create('Ext.data.TreeStore', {
root: {
expanded: true,
children: [
{ text: "Javascript", leaf: true },
{ text: "ASP.net", leaf: true },
{ text: "Also ASP.net", leaf: true }
]
}
});

Ext.create('Ext.tree.Panel', {
title: 'Example Tree',
width: 200,
height: 150,
store: store,
rootVisible: false,
multiSelect: true,
renderTo: Ext.getBody(),
dockedItems: [{
xtype: 'toolbar',
dock : 'bottom',
items : [{
text: 'Search for ASP.net',
handler: function(){
var me = this,
panel = me.up('panel'),
rn = panel.getRootNode(),
regex = new RegExp("ASP.net");

rn.findChildBy(function(child){
var text = child.data.text;
if(regex.test(text) === true){
panel.getSelectionModel().select(child, true);
}
});
}
}]
}]
});

工作 jsFiddle : http://jsfiddle.net/tdaXs/

提示:记下 .select() 中的第二个参数TreePanel的方法的selectionModel 。这是可选的keepExisting参数,必须设置为true手动选择节点时。请参阅文档:http://docs.sencha.com/extjs/4.1.0/#!/api/Ext.selection.Model-method-select

希望这有帮助!

关于javascript - 如何在 extJs 4.1 树面板中突出显示节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18403062/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com