Que*_*low 10 javascript jquery json
我有一个JSON对象,如下所示:
{"data":
[
{"name":"Alan","height":"171","weight":"66"},
{"name":"Ben","height":"182","weight":"90"},
{"name":"Chris","height":"163","weight":"71"}
]
,"school":"Dover Secondary"
}
Run Code Online (Sandbox Code Playgroud)
我想过滤JSON对象以获取高于170且重于70的数据,然后对此对象进行排序.在jQuery网站上,我了解过在线性阵列上很容易实现过滤,例如:
arr = jQuery.grep(arr, function(element, index){
return (element > 70 && index = 'weight');
});
Run Code Online (Sandbox Code Playgroud)
如何同时过滤重量和高度以获得:
{"data":
[
{"name":"Ben","height":"182","weight":"90"},
]
,"school":"Dover Secondary"
}
Run Code Online (Sandbox Code Playgroud)
pim*_*vdb 21
我想你的意思是:http://jsfiddle.net/NRuM7/1/.
var obj = {"data":
[
{"name":"Alan","height":"171","weight":"66"},
{"name":"Ben","height":"182","weight":"90"},
{"name":"Chris","height":"163","weight":"71"}
]
,"school":"Dover Secondary"
};
obj.data = jQuery.grep(obj.data, function(element, index){
return element.weight > 70 && element.height > 170; // retain appropriate elements
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20980 次 |
| 最近记录: |