Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by MandeepS on Mar 05, 2009 13:42
open dhtmlx forum
loadXML(xml, aftercall) - still cannot access tree elements even using aftercall method

I'm having trouble accessing tree elements immediately after loading the tree. But if I put an alert right after the load, then everything works fine. So this alludes to an issue with hitting the tree before it finishes loading. My code is below...please advise.

var globalFieldName = "";
        var globalTree = "";        
        
        function retrieveMetaValues(fieldName, xmlName) {
            var gpreField = document.getElementById(fieldName);
            var gpreValue = gpreField.value;
            globalFieldName = fieldName; //using global var because I cannot pass vars with loadXML() method
            
            if (gpreValue != '' && gpreValue.length != 0) {                
                var newdiv = document.createElement("div");
                newdiv.innerHTML = "<div id='treebox_tree' style='display: none'></div>";
                gpreField.appendChild(newdiv);            
                
                globalTree=new dhtmlXTreeObject("treebox_tree","100%","100%",0);
                globalTree.loadXML('/icons_root/extensions/pw/xml/' + xmlName + '.xml', searchTree());                
            }
        }
        
        // Hits XML to retrieve labels for each codes
        function searchTree() {
            
            //alert('state = ' + globalTree.getXMLState()); //if this line is uncommented, everything works fine!!!!!!
            var fieldName = globalFieldName;
            var gpreField = document.getElementById(fieldName);
            var gpreValue = gpreField.value;                
            
            var splitString = gpreValue.split(",");
            var textString = "";            
            for(var i = 0; i < splitString.length; i++) {                
                textString = textString + globalTree.getItemText(splitString[i]) + '\n';
            }                
            
            var metaField = document.getElementById(fieldName + '_TREE');
            metaField.value = textString; //put text into visible fields            
        }
Answer posted by Alex (support) on Mar 06, 2009 01:59

Please, try to use the following approach to set afterCall function:

globalTree.loadXML('/icons_root/extensions/pw/xml/' + xmlName + '.xml', searchTree);

instead of  

globalTree.loadXML('/icons_root/extensions/pw/xml/' + xmlName + '.xml', searchTree());