Reputation: 307
Hopefully this is a simple question, but I can't seem to get to work.
I'm trying to pass a variable to access a specific array and hide that array's contents.
In this example $prodCat = labialWire. In the .each() I am trying to replace labialWire with $prodCat and hide those objects but it's not working.
jquery:
$('body').on('click', '.deleteLiRadio', function() {
var $prodCat = $(this).data('prodcat'),
$ul = "#upperConfirmUl",
unchecked = new Array();
console.log($prodCat);
$("li[data-prodcat='" + $prodCat + "']").remove();
$('form[data-caturl="' + $prodCat + '"]').trigger('reset');
$($ul).listview( "refresh" );
$($ul).trigger( "updatelayout");
$('form[data-caturl="' + $prodCat + '"] input:not(:checked)').each(function () {
unchecked.push($(this).attr('id'));
});
//console.log(unchecked);
$.each(unchecked, function (i, val) {
labialWire[val] && labialWire[val].hide();/*Replace labialWire with $prodCat*/
});
});
Really appreciate any help!
If it helps, Im getting an undefined response using $prodCat[val].
Upvotes: 2
Views: 98
Reputation: 15893
If labialWire
is a global variable (array):
if (window["labialWire"])
window["labialWire"].[val].hide();
or using a string variable with value "labialWire":
if (window[$prodCat])
window[$prodCat].[val].hide();
Upvotes: 1