【发布时间】:2016-11-26 14:42:00
【问题描述】:
所以我已经有了一个搜索过滤器,但现在我希望它能够combine 搜索短语。下面是在页面上生成列表的代码。
<div class="sortable2">
<ul class="connectedSortable links loadfiles" id="loadfiles">
<?php
foreach ($result as $value) {
list($classname, $origin, $name) = explode('_', $value);
$classname = trim($classname, '[]');
$origin = trim($origin, '[]');
$name = pathinfo($name, PATHINFO_FILENAME);
echo "<li class='audiofile " . $name . " " . $classname . "' id='" . $value . "'>".
"<a class='btn_clone fa fa-clone' aria-hidden='true' id='' onclick='repeat(event)' title='Clone'> </a>".
"<a class='btn_addto fa fa-arrow-up' aria-hidden='true' id='' onclick='addto(event)' title='Add to playlist'> </a>".
"<a class='btn_removefrom fa fa-trash' aria-hidden='true' id='' onclick='removefrom(event)' title='Remove element'> </a>".
"<span class='audioclass'>" . $classname . "</span>".
"<a href='" . $directoryname . "/" . $value . "' target='_blank'>".
"<img src='images/avatars/" . $classname . ".jpg'>".
"<div class='audiotext'>".
"<span class='audiotitle'>" . $name . "</span>".
"<span class='audioorigin'>" . $origin . "</span>".
"</div>".
"</a>".
"</li>";
}
?>
</ul>
</div>
这个列表基本上会生成如下块:
frank
hello how are you
link to audio file
william
i am fine
link to audio file
frank
what?
link to audio file
过滤是通过这段代码完成的
$('#global_filter').keyup(function() {
var col_name = $(this).attr('class');
var search_val = $(this).val().toLowerCase();
$('.' + col_name).closest('#loadfiles > li').css('display', 'none');
$('.' + col_name).each(function() {
var val = $(this).text();
console.log($(this).text(), 'text');
if(val.toLowerCase().indexOf(search_val) >= 0) {
$(this).closest('#loadfiles > li').css('display', 'block');
}
});
});
配合使用
<div class="input">
<h4>Search field</h4>
<div class="all_all" id="filter_global">
<div align="left"><input type="text" name="global_filter" id="global_filter" class="audiofile"></div>
<div align="left"><input type="checkbox" name="global_regex" id="global_regex" ></div>
<div align="left"><input type="checkbox" name="global_smart" id="global_smart" checked></div>
</div>
</div>
问题
如何更改过滤器以允许使用 [AND] 和 [OR] (如果可能)进行多个搜索短语。所以用户可以输入例如:
frank [and] hello
然后这将返回
frank
hello how are you
link to audio file
【问题讨论】:
标签: php search foreach filtering