Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#1607 closed defect (invalid)

AccordionContainer: AccordionPane and singleton bug?

Reported by: joose@… Owned by: bill
Priority: high Milestone:
Component: Widgets Version: 0.4
Keywords: AccordionContainer, AccordionPane Cc:
Blocked By: Blocking:

Description

Can't bind events to single AccordionPane?, seems to be like last event connected to AccordionPane? is the one that gets always executed.

var label=["pane 1", "pane 2", "pane 3"];
for(i=0; i<label.length; ++i) {
   var content = dojo.widget.createWidget("ContentPane", {label: label[i], selected: i==0});
   var ap = accordion.addChild(content);
   dojo.event.connect(ap, "onLabelClick", function() { dojo.debug("label: "+i); });
}

Result: What ever Pane I click: "DEBUG: label: 3"

So, clearly a bug?

Change History (2)

comment:1 Changed 13 years ago by bill

Resolution: invalid
Status: newclosed

Not a bug; you just need to study up a bit more on how closures work. There is only one variable called "i" and after the loop finishes it's value is 3. There are three functions that get called but all the functions reference the same "i" variable.

comment:2 Changed 12 years ago by (none)

Milestone: 0.4

Milestone 0.4 deleted

Note: See TracTickets for help on using tickets.