Create array length number of Accordions

100 Views Asked by At

How can I use the length of an array to create the number of children in an Accordion. For instance, if the length of the array is 8, I create 8 children from the accordion. New to Dojo.

2

There are 2 best solutions below

0
On BEST ANSWER

Assuming that dataArrray is an array of objects holding the data for the contentpane.

require(["dijit/layout/AccordionContainer", "dijit/layout/ContentPane", "dojo/domReady!"],
        function(AccordionContainer, ContentPane){
    var aContainer = new AccordionContainer({style:"height: 300px"}, "markup");
    len = dataArray.length;
    for ( var i =0; i<len; i++);
    {
    aContainer.addChild(new ContentPane({
        title:dataArray[i].title,
        content: dataArray[i].content
    }));
    }
    aContainer.startup();
});
0
On

You'll need to add your content to the contentpanes.

require(["dijit/layout/AccordionContainer", "dijit/layout/ContentPane", "dojo/domReady!"],
        function(AccordionContainer, ContentPane){    
            var acc = new AccordionContainer();
            for(var i = 0; i < arr.length; i++) {
                acc.addChild(new ContentPane());
            }
        });