javascript - Simpler way to combine a if else statement (.contains?) -
javascript - Simpler way to combine a if else statement (.contains?) -
what best way simplify code. thought using .contains i'm unsure how. tell me if need more code.
thank you.
$.each(catalog.products, function(index, value) { if (filtervalue == '' || value.name.touppercase().indexof(filtervalue.tolocaleuppercase()) != -1) { items.push('<li id="' + index + '">' + '<a data-identity="productid" href="./details.page?productid=' + index + '" >' + '<img class="ui-li-thumb" src="' + value.thumbnail + '"/>' + '<p>' + value.brand + '</p>' + '<h3>' + value.name + '</h3>' + '<span class="ui-li-count">' + value.price + ' $</span></li>') + '</a>'; } else if (filtervalue == '' || value.brand.touppercase().indexof(filtervalue.tolocaleuppercase()) != -1) { items.push('<li id="' + index + '">' + '<a data-identity="productid" href="./details.page?productid=' + index + '" >' + '<img class="ui-li-thumb" src="' + value.thumbnail + '"/>' + '<p>' + value.brand + '</p>' + '<h3>' + value.name + '</h3>' + '<span class="ui-li-count">' + value.price + ' $</span></li>') + '</a>'; } } );
it looks simple add-on of or
clause top if statement, or missing something?
have tried this?
$.each(catalog.products, function(index, value) { if (filtervalue == '' || value.name.touppercase().indexof(filtervalue.tolocaleuppercase()) != -1 || value.brand.touppercase().indexof(filtervalue.tolocaleuppercase()) != -1) { items.push('<li id="' + index + '">' + '<a data-identity="productid" href="./details.page?productid=' + index + '" >' + '<img class="ui-li-thumb" src="' + value.thumbnail + '"/>' + '<p>' + value.brand + '</p>' + '<h3>' + value.name + '</h3>' + '<span class="ui-li-count">' + value.price + ' $</span></li>') + '</a>'; } } );
javascript jquery arrays list
Comments
Post a Comment