如何根据多个值搜索数组中的jQuery? 例如,我按颜色和操作系统搜索。 感谢
var products = [
{“id”:“1”,“title”:“Apple iPhone 4”,“os”:“ios”,“color”:“red”}
,{“id”:“2”,“title”:“Blac80 Bold”,“os”:“other”,“color”:“blue”}
,{“id”:“12”,“title”:“黑色0”,“os”:“其他”,“颜色”:“红色”}
,{“id”:“26”,“title”:“HTC s”,“os”:“android”,“color”:“blue”}
,{“id”:“50”,“title”:“HTC HD7”,“os”:“android”,“color”:“red”}
,{“id”:“21”,“title”:“HTC z”,“os”:“android”,“color”:“blue”}
,{“id”:“11”,“title”:“HTC ion”,“os”:“android”,“color”:“red”}
,{“id”:“3”,“title”:“HTC W”,“os”:“android”,“color”:“blue”}
,{“id”:“6”,“title”:“Motorola”,“os”:“ios”,“color”:“blue”}
,{“id”:“14”,“title”:“Motorola DEFY”,“os”:“ios”,“color”:“red”}
,{“id”:“15”,“title”:“诺基亚C7”,“os”:“ios”,“color”:“blue”}
,{“id”:“60”,“title”:“诺基亚N8”,“os”:“ios”,“color”:“red”}
,{“id”:“70”,“title”:“诺基亚X6”,“os”:“ios”,“color”:“blue”} ];
答案 0 :(得分:0)
试试这个..
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script>
$(document).ready(function(){
var products = [
{"id":"1","title":"Apple iPhone 4","os":"ios","color":"red"}
,{"id":"2","title":"Blac80 Bold","os":"other","color":"blue"}
,{"id":"12","title":"Black 0","os":"other","color":"red"}
,{"id":"26","title":"HTC s","os":"android","color":"blue"}
,{"id":"50","title":"HTC HD7","os":"android","color":"red"}
,{"id":"21","title":"HTC z","os":"android","color":"blue"}
,{"id":"11","title":"HTC ion","os":"android","color":"red"}
,{"id":"3","title":"HTC W","os":"android","color":"blue"}
,{"id":"6","title":"Motorola","os":"ios","color":"blue"}
,{"id":"14","title":"Motorola DEFY","os":"ios","color":"red"}
,{"id":"15","title":"Nokia C7","os":"ios","color":"blue"}
,{"id":"60","title":"Nokia N8","os":"ios","color":"red"}
,{"id":"70","title":"Nokia X6","os":"ios","color":"blue"} ];
$.each(products, function(i, v) {
if (v.color == "blue" || v.os == "ios") {
alert(v.title);
return;
}
});
});
</script>