Question

I want to add programatically 4 children to dijit.layout.AccordionContainer. The script runs with no errors, but it only adds 2 children, no matter how I try to achieve this. From my debug using firebug it looks like the scripts stops after adding second child. I tried following suggestions from here, here and here, but I found no solution.

Some code: AccordionContainer definition:

var listaWyjazdow = new dijit.layout.AccordionContainer({}, "target-lista-wyjazdow");

listaWyjazdow.startup();

aktualizujListeWyjazdow();

function to add 4 children to AccordionContainer:

function aktualizujListeWyjazdow(){
dojo.require("dijit.layout.AccordionPane");

var lista = dijit.byId('target-lista-wyjazdow');
lista.destroyDescendants();

var tablica = new dojo.data.ItemFileReadStore({
    url: "logika/getJSON/getWyjazdy.php",
    clearOnClose: true,
    urlPreventCache: true
}).fetch({
    query: {id: '*'},
    sort: {attribute: 'data', descending: true},
    start: 0,
    count: 4,
    onComplete: function(dane){
        console.log(dane);
        var ile = dane.length;
        var i = 0;
        var dzieci = new Array();

                    //this works for 2 children only:
        for (i = 0; i < ile; i++){
            var szczegoly = 'Klient: <strong>' + dane[i].klient + '</strong></br>';
            szczegoly += 'Osoba wyjeżdżająca: <strong>' + dane[i].wyjezdzajacy + '</strong></br>';

            dzieci[i] = new dijit.layout.AccordionPane({
                id: "wyjazd" + i,
                title: "Wyjazd: " + dane[i].data,
                content: szczegoly
            });
            console.log(dane[i]);
            console.log(i + ' - ' + ile);
            lista.addChild(dzieci[i], 0);
            lista.selectChild(dijit.byId('wyjazd' + i));
            //console.log(lista);
        }
                    //this works for 2 children only:
        /*lista.addChild(dzieci[0]);
        console.log(0);
        lista.addChild(dzieci[1]);
        console.log(1);
        lista.addChild(dzieci[2]);
        console.log(2);
        lista.addChild(dzieci[3]);
        console.log(3);*/

                    //this outputs all children:
        /*console.log(dzieci[0]);
        console.log(dzieci[1]);
        console.log(dzieci[2]);
        console.log(dzieci[3]);*/

                    //this works for 2 children only:
        /*for (i = 0; i < ile; i++){
            lista.addChild(dzieci[i]);
            console.log(dzieci[i]);
        }*/
    }
});
}

console output (from firebug):

[Object { id=[1], etykieta=[1], data=[1], more...}, Object { id=[1], etykieta=[1], data=[1], more...}, Object { id=[1], etykieta=[1], data=[1], more...}, Object { id=[1], etykieta=[1], data=[1], more...}]

Object { id=[1], etykieta=[1], data=[1], more...}

0 - 4

Object { id=[1], etykieta=[1], data=[1], more...}

1 - 4

Any help would be greatly appreciated!

EDIT a little update: in my ItemFileReadStore object value returned by url is json:

{
    "identifier": "id",
    "label": "etykieta",
    "items": [
        {
            "id": "1",
            "etykieta": "Wyjazd0",
            "data": "06-10-2011",
            "wyjezdzajacy": "cblajszczak",
            "idKlienta": "1",
            "klient": "klient testowy",
            "zadanieQS": null,
            "dataKolejnegoWyjazdu": null,
            "lacznyCzasWyjazdu": "0"
        },
        {
            "id": "3",
            "etykieta": "Wyjazd1",
            "data": "15-11-2011",
            "wyjezdzajacy": "cblajszczak",
            "idKlienta": "1",
            "klient": "klient testowy",
            "zadanieQS": null,
            "dataKolejnegoWyjazdu": null,
            "lacznyCzasWyjazdu": "0"
        },
        {
            "id": "5",
            "etykieta": "Wyjazd2",
            "data": "30-11-2011",
            "wyjezdzajacy": "cblajszczak",
            "idKlienta": "1",
            "klient": "klient testowy",
            "zadanieQS": null,
            "dataKolejnegoWyjazdu": null,
            "lacznyCzasWyjazdu": "0"
        },
        {
            "id": "4",
            "etykieta": "Wyjazd3",
            "data": "24-11-2011",
            "wyjezdzajacy": "cblajszczak",
            "idKlienta": "2",
            "klient": "hfhhfhd",
            "zadanieQS": null,
            "dataKolejnegoWyjazdu": null,
            "lacznyCzasWyjazdu": "0"
        }
    ]
}

dane[2] has following structure (taken from firebug):

_0 2
_RI true
_S Object { _arrayOfAllItems=[4], _arrayOfTopLevelItems=[4], _loadFinished=true, more...}
data ["30-11-2011"]
[other fields from json structure]

I have noticed that _S shown above contains whole dane array. And this dane contains another _S with whole dane array. And so on, recursively - could this be the problem?

Was it helpful?

Solution

I finally managed to solve my problem. In case anyone else encounters similar problem, the solution is to create container (AccordionContainer in this case) declaratively, not programmatically: <div id="id" style="height:50%" dojoType="dijit.layout.AccordionContainer"></div>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top