I’m lost trying to create and populate arrays.
I have four wrapper panels, which contain div-elements with an id. The id from the div-element with data-show=”first” should be set as first array entry of the respective panel-array.
Here is what I have:
$panels.each(function(index) {
if ( $(this).jqmData('track') == 'history' ) {
var nameSpace = "hist_"+$(this).jqmData('id'),
nameSpace = [];
nameSpace.push({
0:'#'+$(this).find(':jqmData(show="first")').attr('id')
});
}
});
This creates four objects, but I cannot access them using either nameSpace inside the each call or outside using hist_"+$panelName[0]
Can someone tell me what I’m doing wrong? Thanks for help!
Declare
namespaceoutside the loop.Currently, you’re initialising a
nameSpacevariable inside the each. After the declaration, the variable is immediately overwritten by an empty array[], and a new entry is pushed into it. That logic is somewhat flawed.The commented code shows methods to refer through the created data through an array. The current code results in a
namespacevariable in this format: