Visualizzazione dei risultati da 1 a 6 su 6
  1. #1
    Utente di HTML.it
    Registrato dal
    Mar 2001
    Messaggi
    145

    Problema con apice in JavaScript

    Ciao,
    ho un piccolo problema con la gestione di un apice...ho questa riga in ASP:

    Response.Write "Tree[ " & count & "] = """ & id & "|" & dic("livello" & (livello-1)) & "|" & Replace(rs("nome_struttura"),"'","\\'") & "|#"";" & vbCrlf

    che mi crea una riga nel codice HTML tipo: Tree[0] = "1|0|General Manager|#";

    se nome_struttura ha un apice, IE risponde con un errore; idem se metto \\'.
    Con doppio \\\' funziona ma poi nella pagina leggo il nome tipo "Valle d\\'Aosta".

    Come posso risolvere questo piccolo problema?
    Grazie!

  2. #2
    Utente di HTML.it L'avatar di willybit
    Registrato dal
    May 2001
    Messaggi
    4,367
    Ciao Pepito74,

    così non ti si può aiutare, bisognerebbe vedere lo script che utilizza quella stringa.
    (o posti un link dove andare a guardare o posti qui il codice)

  3. #3
    Utente di HTML.it
    Registrato dal
    Mar 2001
    Messaggi
    145
    ok...questo è lo script, messo in un include che viene poi richiamato dalla funzione CreaTree(Tree) che fisicamente me lo scrive su schermo...

    <link rel="StyleSheet" href="tree.css" type="text/css">
    <script type="text/javascript" src="tree.js"></script>
    <script type="text/javascript">
    <!--

    var Tree = new Array;
    // nodeId | parentNodeId | nodeName | nodeUrl
    <%
    query = "SELECT * FROM strutture ORDER BY id_struttura,sub_1,sub_2,sub_3,sub_4,sub_5"
    set rs = server.CreateObject("ADODB.Recordset")
    rs.Open query,Conn,3,3
    if not rs.EOF then
    count = 0
    set dic = Server.CreateObject("Scripting.Dictionary")
    dic.Add "livello0",0
    dic.Add "livello1",0
    dic.Add "livello2",0
    dic.Add "livello3",0
    dic.Add "livello4",0
    dic.Add "livello5",0
    livello=1
    id = 0
    oldId=0
    do while not rs.EOF
    id=id+1
    if livello<=5 then
    if rs("sub_" & livello)>0 then
    dic("livello" & livello) = oldId
    livello=livello+1
    end if
    end if
    if livello>1 then
    if rs("sub_" & (livello-1))=0 then
    for i=livello-1 to 1 step -1
    if rs("sub_" & i)=0 then
    livello=i
    end if
    next
    end if
    end if
    Response.Write "Tree[" & count & "] = """ & id & "|" & dic("livello" & (livello-1)) & "|" & Replace(rs("nome_struttura"),"'","\\'") & "|#;""" & vbCrlf
    oldId=id
    count = count + 1
    rs.MoveNext
    loop
    end if
    %>
    //-->
    </script>

  4. #4
    Utente di HTML.it L'avatar di willybit
    Registrato dal
    May 2001
    Messaggi
    4,367
    quello che serve è il contenuto del file tree.js

  5. #5
    Utente di HTML.it
    Registrato dal
    Mar 2001
    Messaggi
    145
    e allora ditelo!!!

    ecchelo quà:

    /************************************************** ************************
    Copyright (c) 2001-2003 Geir Landrö (drop@destroydrop.com)
    JavaScript Tree - www.destroydrop.com/hjavascripts/tree/
    Version 0.96

    This script can be used freely as long as all copyright messages are
    intact.
    ************************************************** ************************/

    // Arrays for nodes and icons
    var nodes = new Array();;
    var openNodes = new Array();
    var icons = new Array(6);

    // Loads all icons that are used in the tree
    function preloadIcons() {
    icons[0] = new Image();
    icons[0].src = "img/plus.gif";
    icons[1] = new Image();
    icons[1].src = "img/plusbottom.gif";
    icons[2] = new Image();
    icons[2].src = "img/minus.gif";
    icons[3] = new Image();
    icons[3].src = "img/minusbottom.gif";
    icons[4] = new Image();
    icons[4].src = "img/folder.gif";
    icons[5] = new Image();
    icons[5].src = "img/folderopen.gif";
    }
    // Create the tree
    function createTree(arrName, startNode, openNode) {
    nodes = arrName;
    if (nodes.length > 0) {
    preloadIcons();
    if (startNode == null) startNode = 0;
    if (openNode != 0 || openNode != null) setOpenNodes(openNode);

    if (startNode !=0) {
    var nodeValues = nodes[getArrayId(startNode)].split("|");
    document.write("<a href=\"" + nodeValues[3] + "\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\"><img src=\"img/folderopen.gif\" align=\"absbottom\" alt=\"\" />" + nodeValues[2] + "</a>
    ");
    } else document.write("<img src=\"img/base.gif\" align=\"absbottom\" alt=\"\" />HP-DCS
    ");

    var recursedNodes = new Array();
    addNode(startNode, recursedNodes);
    }
    }
    // Returns the position of a node in the array
    function getArrayId(node) {
    for (i=0; i<nodes.length; i++) {
    var nodeValues = nodes[i].split("|");
    if (nodeValues[0]==node) return i;
    }
    }
    // Puts in array nodes that will be open
    function setOpenNodes(openNode) {
    for (i=0; i<nodes.length; i++) {
    var nodeValues = nodes[i].split("|");
    if (nodeValues[0]==openNode) {
    openNodes.push(nodeValues[0]);
    setOpenNodes(nodeValues[1]);
    }
    }
    }
    // Checks if a node is open
    function isNodeOpen(node) {
    for (i=0; i<openNodes.length; i++)
    if (openNodes[i]==node) return true;
    return false;
    }
    // Checks if a node has any children
    function hasChildNode(parentNode) {
    for (i=0; i< nodes.length; i++) {
    var nodeValues = nodes[i].split("|");
    if (nodeValues[1] == parentNode) return true;
    }
    return false;
    }
    // Checks if a node is the last sibling
    function lastSibling (node, parentNode) {
    var lastChild = 0;
    for (i=0; i< nodes.length; i++) {
    var nodeValues = nodes[i].split("|");
    if (nodeValues[1] == parentNode)
    lastChild = nodeValues[0];
    }
    if (lastChild==node) return true;
    return false;
    }
    // Adds a new node to the tree
    function addNode(parentNode, recursedNodes) {
    for (var i = 0; i < nodes.length; i++) {

    var nodeValues = nodes[i].split("|");
    if (nodeValues[1] == parentNode) {

    var ls = lastSibling(nodeValues[0], nodeValues[1]);
    var hcn = hasChildNode(nodeValues[0]);
    var ino = isNodeOpen(nodeValues[0]);

    // Write out line & empty icons
    for (g=0; g<recursedNodes.length; g++) {
    if (recursedNodes[g] == 1) document.write("<img src=\"img/line.gif\" align=\"absbottom\" alt=\"\" />");
    else document.write("<img src=\"img/empty.gif\" align=\"absbottom\" alt=\"\" />");
    }

    // put in array line & empty icons
    if (ls) recursedNodes.push(0);
    else recursedNodes.push(1);

    // Write out join icons
    if (hcn) {
    if (ls) {
    document.write("<a href=\"javascript: oc(" + nodeValues[0] + ", 1);\"><img id=\"join" + nodeValues[0] + "\" src=\"img/");
    if (ino) document.write("minus");
    else document.write("plus");
    document.write("bottom.gif\" align=\"absbottom\" alt=\"Open/Close node\" /></a>");
    } else {
    document.write("<a href=\"javascript: oc(" + nodeValues[0] + ", 0);\"><img id=\"join" + nodeValues[0] + "\" src=\"img/");
    if (ino) document.write("minus");
    else document.write("plus");
    document.write(".gif\" align=\"absbottom\" alt=\"Open/Close node\" /></a>");
    }
    } else {
    if (ls) document.write("<img src=\"img/joinbottom.gif\" align=\"absbottom\" alt=\"\" />");
    else document.write("<img src=\"img/join.gif\" align=\"absbottom\" alt=\"\" />");
    }

    // Start link
    document.write("<a href=\"" + nodeValues[3] + "\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\">");

    // Write out folder & page icons
    if (hcn) {
    document.write("<img id=\"icon" + nodeValues[0] + "\" src=\"img/folder")
    if (ino) document.write("open");
    document.write(".gif\" align=\"absbottom\" alt=\"Folder\" />");
    } else document.write("<img id=\"icon" + nodeValues[0] + "\" src=\"img/page.gif\" align=\"absbottom\" alt=\"Page\" />");

    // Write out node name
    document.write(nodeValues[2]);

    // End link
    document.write("</a>
    ");

    // If node has children write out divs and go deeper
    if (hcn) {
    document.write("<div id=\"div" + nodeValues[0] + "\"");
    if (!ino) document.write(" style=\"display: none;\"");
    document.write(">");
    addNode(nodeValues[0], recursedNodes);
    document.write("</div>");
    }

    // remove last line or empty icon
    recursedNodes.pop();
    }
    }
    }
    // Opens or closes a node
    function oc(node, bottom) {
    var theDiv = document.getElementById("div" + node);
    var theJoin = document.getElementById("join" + node);
    var theIcon = document.getElementById("icon" + node);

    if (theDiv.style.display == 'none') {
    if (bottom==1) theJoin.src = icons[3].src;
    else theJoin.src = icons[2].src;
    theIcon.src = icons[5].src;
    theDiv.style.display = '';
    } else {
    if (bottom==1) theJoin.src = icons[1].src;
    else theJoin.src = icons[0].src;
    theIcon.src = icons[4].src;
    theDiv.style.display = 'none';
    }
    }
    // Push and pop not implemented in IE
    if(!Array.prototype.push) {
    function array_push() {
    for(var i=0;i<arguments.length;i++)
    this[this.length]=arguments[i];
    return this.length;
    }
    Array.prototype.push = array_push;
    }
    if(!Array.prototype.pop) {
    function array_pop(){
    lastElement = this[this.length-1];
    this.length = Math.max(this.length-1,0);
    return lastElement;
    }
    Array.prototype.pop = array_pop;
    }

  6. #6
    Utente di HTML.it L'avatar di willybit
    Registrato dal
    May 2001
    Messaggi
    4,367
    una soluzione buttata li potrebbe essere quella di tenere il doppio backslash prima dell'apice che così non vengono fuori errori e in visualizzazione eliminare il backslash in più
    metti all'inizio dello script questa regular expression e sostituisci le due funzioni con queste
    codice:
    var reSlash = /\\/g
    
    // Create the tree
    function createTree(arrName, startNode, openNode) {
    	nodes = arrName;
    	if (nodes.length > 0) {
    		preloadIcons();
    		if (startNode == null) startNode = 0;
    		if (openNode != 0 || openNode != null) setOpenNodes(openNode);	
    		if (startNode !=0) {
    			var nodeValues = nodes[getArrayId(startNode)].split("|");
    			str = "<a href=\"" + nodeValues[3] + "\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\"><img src=\"img/folderopen.gif\" align=\"absbottom\" alt=\"\" />" + nodeValues[2].replace(reSlash,'') + "</a>
    "
    			document.write(str);
    		} else document.write("<img src=\"img/base.gif\" align=\"absbottom\" alt=\"\" />HP-DCS
    ");
    	
    		var recursedNodes = new Array();
    		addNode(startNode, recursedNodes);
    	}
    }
    
    
    // Adds a new node to the tree
    function addNode(parentNode, recursedNodes) {
    	for (var i = 0; i < nodes.length; i++) {
    
    		var nodeValues = nodes[i].split("|");
    		if (nodeValues[1] == parentNode) {
    			
    			var ls	= lastSibling(nodeValues[0], nodeValues[1]);
    			var hcn	= hasChildNode(nodeValues[0]);
    			var ino = isNodeOpen(nodeValues[0]);
    
    			// Write out line & empty icons
    			for (g=0; g<recursedNodes.length; g++) {
    				if (recursedNodes[g] == 1) document.write("<img src=\"img/line.gif\" align=\"absbottom\" alt=\"\" />");
    				else  document.write("<img src=\"img/empty.gif\" align=\"absbottom\" alt=\"\" />");
    			}
    
    			// put in array line & empty icons
    			if (ls) recursedNodes.push(0);
    			else recursedNodes.push(1);
    
    			// Write out join icons
    			if (hcn) {
    				if (ls) {
    					document.write("<a href=\"javascript: oc(" + nodeValues[0] + ", 1);\"><img id=\"join" + nodeValues[0] + "\" src=\"img/");
    					 	if (ino) document.write("minus");
    						else document.write("plus");
    					document.write("bottom.gif\" align=\"absbottom\" alt=\"Open/Close node\" /></a>");
    				} else {
    					document.write("<a href=\"javascript: oc(" + nodeValues[0] + ", 0);\"><img id=\"join" + nodeValues[0] + "\" src=\"img/");
    						if (ino) document.write("minus");
    						else document.write("plus");
    					document.write(".gif\" align=\"absbottom\" alt=\"Open/Close node\" /></a>");
    				}
    			} else {
    				if (ls) document.write("<img src=\"img/joinbottom.gif\" align=\"absbottom\" alt=\"\" />");
    				else document.write("<img src=\"img/join.gif\" align=\"absbottom\" alt=\"\" />");
    			}
    
    			// Start link
    			document.write("<a href=\"" + nodeValues[3] + "\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\">");
    			
    			// Write out folder & page icons
    			if (hcn) {
    				document.write("<img id=\"icon" + nodeValues[0] + "\" src=\"img/folder")
    					if (ino) document.write("open");
    				document.write(".gif\" align=\"absbottom\" alt=\"Folder\" />");
    			} else document.write("<img id=\"icon" + nodeValues[0] + "\" src=\"img/page.gif\" align=\"absbottom\" alt=\"Page\" />");
    			
    			// Write out node name
    			document.write(nodeValues[2].replace(reSlash,''));
    
    			// End link
    			document.write("</a>
    ");
    			
    			// If node has children write out divs and go deeper
    			if (hcn) {
    				document.write("<div id=\"div" + nodeValues[0] + "\"");
    					if (!ino) document.write(" style=\"display: none;\"");
    				document.write(">");
    				addNode(nodeValues[0], recursedNodes);
    				document.write("</div>");
    			}
    			
    			// remove last line or empty icon 
    			recursedNodes.pop();
    		}
    	}
    }
    famme sape'

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.