Tabbar items not available until page loading is finished

Hi,

I have a buildInterface() function which is called :

dhtmlxEvent(window,“load”,buildInterface);

Then I have this code

buildInterface()
{

alert('Build Started');

........other code..............

tbar.loadXML("xml/gettoolbar.php",function(){

                tbar.forEachItem(function(itemId){
                    counter++;
                });
               
               alert('Total Items:'+counter);
                
            });

..... other code..........

alert('BuildInterface() Over');

} //buildInterface end

For some reason which I don’t understand, the alerts are displayed like this:

1st alert : “Build Started”

2nd alert: “BuildInterface() Over”

3rd alert: “Total Items: 5”

Why I don’t see the “Total items” alert before buildinterface() is over? What can I do to fix this?

Thanks

Hi,

loadXML loads data asynchronously. For this reason, you use loading handler to call forEachItem method.

So, it is correct behavior that load is ended after alert(‘BuildInterface() Over’) called.

What should I do to count items then?

Does not your approach work to count items ?

tbar.loadXML(“xml/gettoolbar.php”,function(){
tbar.forEachItem(function(itemId){
counter++;
});
alert(‘Total Items:’+counter);
})

No it doesn’t.

After LoadXML I also have

tbar.loadXML("xml/gettoolbar.php",function(){

                tbar.forEachItem(function(itemId){
                    counter++;
                });
               
               alert('Total Items:'+counter);
                
            });


toolbar.addButton("button_1",counter, .......);
toolbar.addButton("button_2",counter+1, .......);

These buttons are inserted at position 0 , but I want them to be added to the end of the toolbar.

I tried to put a high number in position but they are still added at the beginning. If loading is done asynchronously then there is nothing in the toolbar and that’s the reason they are added in the beginning.

I have to find a way to let the toolbar load and then add the buttons.

I will just put it inside the forEach loop. That should do it.

EDIT: after the forEach loop I meant