按名称、价格筛选JQuery列表..json数组,JQuery.grep()
Filter JQuery list by name, price... json array, JQuery.grep()
我刚刚收到了上一个问题的惊人反馈,但现在我又陷入了困境。
我有一个JQuery列表视图,显示我的json数组。它运行良好。但现在,我希望能够按名称或价格过滤我的结果。我查找了jQuery.grep()方法,但无法使其正常工作。
如果有人能给我一些建议,告诉我如何让它发挥作用,我将再次不胜感激。
这是我目前掌握的代码:
js文件:
//Json阵列var productList={"products":[{"description":"Product 1","price":"9.99$"},{"description":"Product 2","price":"9.97$"},{"描述":"产品3","价格":"8.52$"},{"描述":"产品4","价格":"5.24$"},{"描述":"产品5","价格":"4.21$"}]};function loadList() { // var list = document.getElementById('productList'); var list = $("#productList").listview(); list.sort(); $(productList.products).each(function(index){ $(list).append('<li id="listitem">' + this.description + " " + " : " + this.price + '</li>'); }); $(list).listview("refresh"); }<code>
HTML文件:
<html> <head> <title>Product List</title> &meta; <script src="@=site.cfg.resources.url@/test.js"></script> </head> <body onLoad="loadList()"> <div data-role="page"> <div data-role="header" id="header"> <h1>Product List</h1> </div> <div data-role="content" id="content"> <ul id="productList" data-role="listview" data-inset="true" data-theme="c" data-dividertheme="b"> </ul> </div> </div> </body> </html>
.filter()应该能满足您的需求。
$.grep()
值得一看。
相关文章:
- jQuery数组乘法
- 简单JQuery数组
- 缺陷的JQuery数组,实现不起作用
- Jquery数组-设置和加载值
- jQuery数组参数和each()
- Jquery数组查询不起作用
- 如何对jquery数组中的项执行函数
- 从 javascript 数组创建一个 Jquery 数组
- 循环JQuery数组
- 从jQuery数组或元素的对象列表中选择第N个项目
- 如何在jQuery数组中保存行的每一列的内容
- 获取jquery数组对象的第n项
- jQuery 数组迭代
- Jquery 数组通配符
- 如何从jquery数组中删除双引号
- 如何在单引号内添加每个 jquery 数组值
- 如何使用 Ajax 调用将 jQuery 数组传递到 Spring 中
- 如何将jquery数组添加到html表单中,以将复选框动态添加到对话框中
- 创建循环设置超时 jquery 数组
- 按名称查找 jquery 数组