我有这个JQuery/Javascript的代码块来筛选我的名单的搜索条件。这很长,看起来有点不专业。有什么办法可以简化它吗?寻找一种方法来简化含有多个||的if语句
喜欢什么“.contains()”?
如果有人能指出我在正确的方向,我将不胜感激。谢谢 !
继承人的代码;问我,如果你需要更多的:
$.each(catalog.products,
function(index, value) {
if ((filterValue == '' || filterValue == null)
|| value.name.toUpperCase().indexOf(filterValue.toUpperCase()) != -1
|| value.brand.toUpperCase().indexOf(filterValue.toLocaleUpperCase()) != -1
|| value.category.toUpperCase().indexOf(filterValue.toUpperCase()) != -1
|| value.sport.toUpperCase().indexOf(filterValue.toUpperCase()) != -1)
{
items.push('<li id="' + index + '">' +
'<a data-identity="productId" href="./details.page?productId=' + index + '" >' +
'<img class="ui-li-thumb" src="' + value.thumbnail + '"/>' +
'<p>' + value.brand + '</p>' +
'<h3>' + value.name + '</h3>' +
'<span class="ui-li-count">' + value.price + ' $</span></li>') +
'</a>';
}
}
);
如果这是您需要的逻辑,那么它是*简化*。可读性也有一些需要说明的地方。 –
codereview.stackexchange.com – bevacqua
我认为http://codereview.stackexchange.com/是正确的网站要问 – Sotiris