我需要修改一些已經存在的代碼。有一段代碼可以使用URL過濾JQuery列表來填充搜索輸入。用URL過濾JQuery列表
E.g.
http://***/store/mobile/page/productList.page?search=football
自動在搜索欄中輸入「足球」。
現在我需要過濾列表,而不使用搜索欄。
因此,可以說我的URL會是這個樣子:
http://***/store/mobile/page/productList.page?football
這將過濾與足球列表不使用搜索欄。
下面是我需要更改的代碼。請告訴我,如果我的問題不清楚。
$('div[data-url*="productList"]').live("pageshow", function() {
filterValue = getParameterByName("search", location.search);
if (filterValue) {
$('input[data-type="search"]').val(filterValue);
}
refreshList();
});
和:
$.each(catalog.products,
function(index, value) {
if ((!filterValue)
|| value.name.toUpperCase().indexOf(filterValue.toUpperCase()) != -1
|| value.brand.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>';
}
});
你可能要剪掉領先from window.location.search –