I have a problem with my code bellow:
for (var i =0; i < filterArray.length; i++)
{
name1 = filterArray[i];
selectstring = 'a[cat="'+name1+'"]';
filterMenuItem.addItem(name1 , function() {$(selectstring).show(); alert(selectstring)});
}
filterArray contains 2 items currently.. "Foo" & "Bar"..
now this "addItem(name1" works fine. We get an added menu item with the name Foo and another named Bar
the issue comes with the next part (the function).
both the Foo & Bar menu items functions end up doing the same thing. (e.g. they both get the select string 'a[cat="bar"]'... as tested with the alert)
Now i assume this is happening because the selectstring variable is being passed by reference to the function? So when i'm setting selectstring value a second time it is overriding the value from the first loop?
How can I pass a unique copy of selectstring to a selector? i tried "function(selectstring) {....}" but this didn't help..
Thanks for anyone who can shed some light on the subject!
EDIT: Revised code below.. Still same issue:
for (var i =0; i < filterArray.length; i++)
{
var name1 = filterArray[i];
var selectstring = 'a[cat="'+name1+'"]';
filterMenuItem.addItem(name1 , function() {alert(selectstring); $('.sortablelist').hide(); $(selectstring).show();});
}