gleenk
3/23/2015 - 3:05 PM

Filtra Array Multiplo jQuery

Filtra Array Multiplo jQuery

$(function(){
	var items = [
	    { id: 01, categoria: "Sport", posizione: "Esterno", metri1 : 2, metri2: 1, prezzo: "€3.888,00"},
	    { id: 02, categoria: "Sport", posizione: "Esterno", metri1 : 2, metri2: 2, prezzo: "€6.738,00"},
	    { id: 03, categoria: "Sport", posizione: "Esterno", metri1 : 2, metri2: 3, prezzo: "€9.576,00"}
	];
	   
	   
	var filteredItems = $(items).filter(function( idx ) {
	    return items[idx].categoria == "Sport" && items[idx].posizione == "Esterno" && items[idx].metri1 == 2 && items[idx].metri2 == 2;
	}); 

	$(filteredItems).each(function(){
	     $('#output').append(this.id+" : "+this.prezzo+"<br>");
	});
});
<!DOCTYPE html>
<html lang="it" dir="ltr">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width,initial-scale=1.0">
	<title>Titolo del Progetto</title>
	<meta name="description" content="Descrizione Meta">
	<link rel="profile" href="http://gmpg.org/xfn/11">
	<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
	<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
	<script type="text/javascript" src="filter.js"></script>
	<!--[if lt IE 9]>
		<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
		<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
	<![endif]-->
</head>
<body>

<div id="output"></div>

</body>
</html>