#1607 closed defect (invalid)
AccordionContainer: AccordionPane and singleton bug?
Reported by: | 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?
Note: See
TracTickets for help on using
tickets.
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.