gpt4 book ai didi

带有 Kendo UI Panelbar 的 JavaScript 搜索栏

转载 作者:行者123 更新时间:2023-11-30 11:07:54 27 4
gpt4 key购买 nike

有人可以帮我搜索 Kendo UI 面板栏吗?

  1. 当搜索时,我希望它显示在 type='program' 上。例如,如果我搜索帐户,应该会出现包含帐户字词的程序。
  2. 目前它根本不起作用。它只是扩展了我所有的面板栏程序。 :(

我在这里提供dojo demo

我的javascript

function myFunction() {

var panelbar = $("#panelbar").data("kendoPanelBar");
panelbar.expand($("li", panelbar.element));
//panelbar.collapse($("li", panelbar.element));

var input, filter, ul, li, a, i, txtValue;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
ul = document.getElementById("panelbar");
li = ul.getElementsByTagName("li");

for (i = 0; i < li.length; i++) {
a = li[i].getElementsByTagName("li")[0];
txtValue = a.textContent || a.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
li[i].style.display = "";
} else {
li[i].style.display = "none";
}
}
}

基本上我的嵌套列表是这样的

<ul id="panelbar">
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search...">
<li type="module">Agencies &amp; Groups
<ul>
<li type="category">Agency &amp; Booker
<ul>
<li type="program">Agency &amp; Booker</li>
<li type="program">Region</li>
<li type="program">Sub Region</li>
</ul>
</li>
<li type="program">Agency Category</li>
<li type="program">Agency Contract</li>
<li type="program">Agency Overview</li>
</ul>
</li>
<li type="module">Call Charge &amp; Billing
<ul>
<li type="category">JDS
<ul>
<li type="program">JDS Room Mapping</li>
<li type="program">JDS Room Status</li>
<li type="program">DS Interface</li>
</ul>
</li>
<li type="category">Operator Panel
<ul>
<li type="program">Wake Up Call</li>
<li type="program">Operator Panel</li>
</ul>
</li>
<li type="program">Call Code</li>
<li type="program">Charge Rate</li>
<li type="program">Property PABX</li>
<li type="program">Call Transaction</li>
</ul>
</li>

我在这里提供dojo demo

最佳答案

输入 <LI> type属性用于项目符号类型。将您的类型值(即层次结构级别分类值)放在类属性中。变化

<li type="category" label=""><span class="k-icon ehors-subfolder-icon"></span>Account's Ledger … 

<li class="category" label=""><span class="k-icon ehors-subfolder-icon"></span>Account's Ledger ….

id value 在所有 DOM 元素中应该是唯一的(除了单选按钮)。叶子都具有相同 id 值的跨度,id="spanpanelbar" .也将它们放在类属性中。变化

<li type="program"><span id="spanpanelbar" class="k-icon ehors-folderopen-icon"></span>General Ledger</li>

<li class="program"><span class="spanpanelbar k-icon ehors-folderopen-icon"></span>General Ledger</li>

搜索匹配结果处理仅更改样式 display叶子的属性。更改处理以将类添加到 <li> ,对应搜索结果条件。

style
.program.nomatch {display:block; color: lightgray } /* or simply display: none */
.program.match {display:block; }

javascript
match = $(this).text().match(searchRegEx);
$li = $(this);
$li.toggleClass("match", (match!=null)).toggleClass("nomatch",(match==null));

查看此 dojo ,您原来的更新。它有红利代码:

  • 等待输入停止
  • 突出显示匹配的片段

enter image description here

PanelBar 小部件是分层查看器。必须显示程序路径中的项目才能看到该程序。为了只显示找到的程序的路径,你会:

  • 在搜索开始时将所有项目设置为具有nomatch 类(隐藏所有内容)
  • 匹配完成后,将程序及其父项设置为具有匹配类(取消隐藏程序路径)

例子:

    // hide top and middle tier so they wont show if there are no
// subordinate programs that match

$("li.category").toggleClass("nomatch", true).toggleClass("match",false);
$("li.module") .toggleClass("nomatch", true).toggleClass("match",false);

// evaluate each program for matching the search term

$("#panelbar li.program").each(function() {
var match, $li, $span, textnode, element;

match = $(this).text().match(searchRegEx);
$li = $(this);

// hide/display programs according to match result

$li.toggleClass("match", (match!=null))
.toggleClass("nomatch",(match==null));

// display items in path when match made

if (match!=null) {
$li.parentsUntil("#panelbar", "li")
.toggleClass("match",true)
.toggleClass("nomatch",false);
}

dojo

关于带有 Kendo UI Panelbar 的 JavaScript 搜索栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54937347/

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