Search code examples
javascriptarraysdojodojox.chartingaccordionpane

Create array length number of Accordions


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.


Solution

  • 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();
    });