Domanda

Ho usato il seguente codice js per espandere / comprimere tutti i nodi di un controllo TreeView ASP.Net:

// handle tree - this doesn't seem to work when the tree contains node images
function TreeviewExpandCollapseAll(treeViewId, expandAll) {
    var displayState = (expandAll == true ? "none" : "block");
    var treeView = document.getElementById(treeViewId);
    if (treeView) {
        var treeLinks = treeView.getElementsByTagName("a");
        var nodeCount = treeLinks.length;
        alert(nodeCount);

        for (i = 0; i < nodeCount; i++) {
            if (treeLinks[i].firstChild.tagName) {
                if (treeLinks[i].firstChild.tagName.toLowerCase() == "img") {
                    var currentToggleLink = treeLinks[i];
                    var childContainer = GetParentByTagName("table", currentToggleLink).nextSibling;
                    if (childContainer.style.display == displayState) {
                        eval(currentToggleLink.href);
                    }
                }
            }
        } //for loop ends
    }
}

//utility function to get the container of an element by tagname
function GetParentByTagName(parentTagName, childElementObj) {
    var parent = childElementObj.parentNode;
    while (parent.tagName.toLowerCase() != parentTagName.toLowerCase()) {
        parent = parent.parentNode;
    }
    return parent;
} 

Il problema è che quando ho NodeStyle-ImageUrl = " img / FolderSmall.gif " , l'espansione fallisce dopo l'apertura del primo nodo figlio - SOLO quando sono presenti immagini di nodi.

L'errore JS è childContainer è null:

                    if (childContainer.style.display == displayState) {
                        eval(currentToggleLink.href);

Sono sicuro che qualcun altro si è imbattuto in questo, ma tutto il codice che ho trovato per espandere / comprimere fallisce nello stesso punto.

È stato utile?

Soluzione

Questo è in realtà un po 'di tempo fa, ma se ricordo bene, ho semplicemente incluso un segnaposto immagine 1px per non restituire null su qualsiasi chiamata.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top