开发者

jQuery filter function is not showing exact match :(

开发者 https://www.devze.com 2023-01-28 15:40 出处:网络
My problem is something like this, I am using filter function to show the matched elements(LI)in tree,its working fine but its showing all li elements which starts from passed string,for example

My problem is something like this,

I am using filter function to show the matched elements(LI)in tree,its working fine but its showing all li elements which starts from passed string,for example

if i passed "Application" to filter function,then it's showing me all li, which text start from "Application"

function callme(filterData){
$("ul.treeview").find("li").hide();
if(filterData.indexOf("|")!=-1){
    var filterData = filterData.split("|");

for(i=0;i<filterData.length;i++){

jQuery("ul.treeview").find("li").filter(function(index) { return jQuery.trim($(this).text()) == filterData.trim(); }).show(); }

}else{ jQuery("ul.treeview").find("li").filter(function(index) { return jQuery.trim($(this).text()) == filterData.trim(); }).show();

} }

here is my html...

<ul id="leftNavigation" class="treeview"> <li> <ul> <li > <a href="#">Application</a><font class="leftNavHitsFont"> - (3)<开发者_StackOverflow中文版/font> </li> </ul> <ul> <li > <a href="#">Application Notes</a><font class="leftNavHitsFont"> - (1)</font> </li> </ul> </li> </ul>


Yeah, that is the definition of something containing something else.

Maybe you meant to get an exact match?

jQuery("ul.treeview").find("li").filter(function(index) {
    return jQuery.trim($(this).text()) == jQuery.trim(filterData);
}).show();

jsFiddle example

0

精彩评论

暂无评论...
验证码 换一张
取 消