Display only certain list items in listview with javascript -
i have made listview of jquery mobile , it's displaying 4 list items. list generated javascript.
$( document ).ready(function() { var data = [{ "name": "lichtbediening", "category": "category", "info": "klik voor lichtbediening", "img": "lichtbediening" }, { "name": "stopcontact", "category": "category", "info": "klik voor stopcontacten", "img": "stopcontacten" }, { "name": "enkele schakelaar", "info": "een knop, een lamp", "img": "rolluikbediening" }, { "name": "dubbele schakelaar", "info": "twee knoppen, twee lampen", "img": "multimedia" }]; var output = ''; $.each(data, function (index, value) { output += '<li><a href="#">' output += '<img src="img/' + value.img + '.jpg">' output += '<h2>' + value.name +'</h2>' output += '<p>' + value.info + '</p>' output += '</a></li>'; }); $('#list_zoek_category').html(output).listview("refresh"); });
at moment displays "each" row in data list item in list. want display listitems category == category.
does have idea how can make work?
do below
$.each(data, function (index, value) { if(value.category != 'category') return; // if value.category not equal 'category` nothing, exit. output += '<li><a href="#">' output += '<img src="img/' + value.img + '.jpg">' output += '<h2>' + value.name +'</h2>' output += '<p>' + value.info + '</p>' output += '</a></li>'; });
Comments
Post a Comment