En este grupo En todos

Foro de ASP



Arbol en asp no me funciona si parent es

Necora01
Lugo, España
Escrito por Necora01
el 06/10/2009
De principio estoy empezando en esto de asp y he encontrado un árbol basado en omentree. La BBDD tiene los campos text (para el nombre) key (para el usuario) y parent (para identificar el padre). Necesito que el campo parent y key no sean numericos sino texto. Si los cambio no me funciona el codigo he intentado revisar y poner " en varios sitios porque se supone que tendría que decirle a las consultas que es texto pero no consigo resultados ¿Me podeis ayudar?
<%@ Language=VBScript %>
<%
Function nodelist(parent)
SQLStmt = "SELECT key, parent, text FROM Nodes WHERE parent=" & parent & ""
Set RS = Connection. Execute(SQLStmt)
Do While Not RS. EOF
tempID = RS("parent")
If tempID = 0 Then tempID = 1
Set RSTemp = Connection. Execute("SELECT key, parent, text FROM Nodes WHERE parent=" & RS("key"))
If RSTemp. EOF = False Then
If RS("parent") = 0 Then "this one"s directly below the Root
txtjscript = "treeData. Add(new FolderNode(""_" & Trim(RS(0)) & """,""root"",""" & Trim(RS(2)) & ""","""","""",""page2. Asp? NodeId=" & RS(0) & """," & RS(0) & "));"
Else
txtjscript = "treeData. Add(new FolderNode(""_" & Trim(RS(0)) & """,""_" & RS(1) & """,""" & Trim(RS("text")) & """,""img-folder-closed-1. Gif"",""img-folder-open-1. Gif"",""page2. Asp? NodeId=" & RS(0) & """," & RS(0) & "));"
End If
Else
If RS("parent") = 0 Then "this one"s directly below the Root
txtjscript = "treeData. Add(new FolderNode(""_" & Trim(RS(0)) & """,""root"",""" & Trim(RS(2)) & """,""img-folder-closed-fav. Gif"",""img-folder-closed-fav. Gif"",""page2. Asp? NodeId=" & RS(0) & """," & RS(0) & "));"
Else
txtjscript = "treeData. Add(new LinkNode(""_" & RS(1) & """,""" & Trim(RS(2)) & """,""page2. Asp? NodeId=" & RS(0) & ""","""",""img-page. Gif""," & RS(0) & "));"
End If
End If
Mainjscript = Mainjscript & txtjscript & vbCrLf
Set RSTemp = Nothing
xNodes = xNodes + 1
nodeindent = nodeindent + 1
nodelist RS(0)
nodeindent = nodeindent - 1
If xNodes >= nNodes Then "Just to be on the save side
Exit Do
Exit Function
End If
RS. MoveNext
Loop
End Function
Dim nodeindent, nNodes, Mainjscript
Set Connection = Server. CreateObject("ADODB. Connection")
Connection. Open "DRIVER={Microsoft Access Driver (*. Mdb)}; DBQ=" & Server. MapPath("tree. Mdb")
Set RSnNodes = Connection. Execute("SELECT Count(Nodes. Key) AS nId FROM Nodes")
nNodes = RSnNodes("nId")
Set RSnNodes = Nothing
targetFrame = "pageFrame"
nodelist 0
%><! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4. 0 Frameset//EN">
<html>
<head>
<meta http-equiv="expires" content="-1">
<meta http-equiv="pragma" content="no-cache">
<title>Isis</title>
<script language="javascript" type="text/javascript">
<! -- Begin Hiding
function start() {
loadData();
drawTree();
}
function drawTree() {
outputFrame = top.treeFrame.window. Document;
outputFrame. Open("text/html");
outputFrame. Write("<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1. 0 Transitional//EN" ");
outputFrame. Write(""https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional. Dtd "> ");
outputFrame. Write("
<html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
");
outputFrame. Write("
<head>
");
/*
Netscape 4. 7* seems to reload the frame when a character set is specified!?
outputFrame. Write("
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
");
*/
outputFrame. Write("
<meta http-equiv="Expires" content="0" />
");
outputFrame. Write("
<meta http-equiv="Cache-Control" content="no-cache" />
");
outputFrame. Write("
<meta http-equiv="Pragma" content="no-cache" />
");
outputFrame. Write("
<link rel="stylesheet" type="text/css" href="tree. Css" media="screen" />
");
outputFrame. Write("
</head>
");
outputFrame. Write("
<body bgcolor="" + backgroundColor + "" background="" + backgroundImage + "" link="" + linkColor + "" alink="" + aLinkColor + "" vlink="" + vLinkColor + "">
");
outputFrame. Write("<form name="Form"> ");
outputFrame. Write("<font face="" + omenTreeFont + "" size="" + omenTreeFontSize + "" color="" + textColor + ""> ");
outputFrame. Write(prefixHTML + " <nobr> ");
if (treeData[1]. Target == "") {var targetFrame = defaultTargetFrame} else {var targetFrame = treeData[1]. Target}
drawBranch("root","");
outputFrame. Write("</nobr> " + suffixHTML + " ");
outputFrame. Write("</font> </form>
</body>

</html>
");
outputFrame. Close();
window. Status="";
}
function drawBranch(startNode,structureString) {
var children = extractChildrenOf(startNode);
var currentIndex = 1;
while (currentIndex <= children. Length) {
outputFrame. Write(structureString);
if (children[currentIndex]. Type == "link") {
if (children[currentIndex]. Icon == "") {
var imageString = defaultImageURL + defaultLinkIcon;
}else {var imageString = defaultImageURL + children[currentIndex]. Icon}
if (children[currentIndex]. Target == "") {
var targetFrame = defaultTargetFrame;
}else {var targetFrame = children[currentIndex]. Target}
if (currentIndex! = children. Length) {
outputFrame. Write("<img src="" + defaultImageURL + "img-branch-cont-" + structureStyle + ". Gif" width="19" height="16" align="texttop" />")
}else {
outputFrame. Write("<img src="" + defaultImageURL + "img-branch-end-" + structureStyle + ". Gif" width="19" height="16" align="texttop" />")
}
outputFrame. Write("<img src="" + imageString + "" width="16" height="16" align="absmiddle" border="0" alt="" + children[currentIndex]. Name + "">&nbsp;<a href="" + children[currentIndex]. Url + "" onmouseover="window. Status="" + children[currentIndex]. Name + ""; return true" target="<%=targetFrame%>" id="_" + children[currentIndex]. Dbid + "" onclick="" + "parent. Setthestate("_" + children[currentIndex]. Dbid + "","" + children[currentIndex]. Url +"");return false">" + children[currentIndex]. Name + "&nbsp;</a><br /> ")
}else {
var newStructure = structureString;
if (children[currentIndex]. IconClosed == "") {var iconClosed = "img-folder-closed-" + structureStyle + ". Gif"} else {var iconClosed = children[currentIndex]. IconClosed}
if (children[currentIndex]. IconOpen == "") {var iconOpen = "img-folder-open-" + structureStyle + ". Gif"} else {var iconOpen = children[currentIndex]. IconOpen}
if (currentIndex! = children. Length) {
if (children[currentIndex]. Open == 0) {
outputFrame. Write("<a href="javascript:top. ToggleFolder("" + children[currentIndex]. Id + "",1)" onmouseover="window. Status="Haz click para abrir esta carpeta"; return true"><img src="" + defaultImageURL + "img-plus-cont-" + structureStyle + ". Gif" width="19" height="16" alt="Haz click para abrir esta carpeta" align="texttop" border="0" />")
outputFrame. Write("<img src="" + defaultImageURL + iconClosed + "" width="16" height="16" align="absmiddle" alt="Haz click para abrir esta carpeta" border="0" /></a>&nbsp;<a href="" + children[currentIndex]. Url + "" target="<%=targetFrame%>" id="_" + children[currentIndex]. Dbid + "" onclick="parent. Setthestate("_" + children[currentIndex]. Dbid + "","" + children[currentIndex]. Url +"");return false">" + children[currentIndex]. Name + "&nbsp;</a><br /> ")
}else {
outputFrame. Write("<a href="javascript:top. ToggleFolder("" + children[currentIndex]. Id + "",0)" onmouseover="window. Status="Haz click para cerrar esta carpeta"; return true"><img src="" + defaultImageURL + "img-minus-cont-" + structureStyle + ". Gif" width="19" height="16" alt="Haz click para cerrar esta carpeta" align="texttop" border="0">");
outputFrame. Write("<img src="" + defaultImageURL + iconOpen + "" width="16" height="16" align="absmiddle" alt="Haz click para cerrar esta carpeta" border="0" /></a>&nbsp;<a href="" + children[currentIndex]. Url + "" target="<%=targetFrame%>" id="_" + children[currentIndex]. Dbid + "" onclick="parent. Setthestate("_" + children[currentIndex]. Dbid + "","" + children[currentIndex]. Url +"");return false">" + children[currentIndex]. Name + "&nbsp;</a><br /> ");
newStructure = newStructure + "<img src="" + defaultImageURL + "img-vert-line-" + structureStyle + ". Gif" width="19" height="16" align="texttop" />";
drawBranch(children[currentIndex]. Id,newStructure);
}
}else {
if (children[currentIndex]. Open == 0) {
outputFrame. Write("<a href="javascript:top. ToggleFolder("" + children[currentIndex]. Id + "",1)" onmouseover="window. Status="Haz click para abrir esta carpeta"; return true"><img src="" + defaultImageURL + "img-plus-end-" + structureStyle + ". Gif" width="19" height="16" alt="Haz click para abrir esta carpeta" align="texttop" border="0" />")
outputFrame. Write("<img src="" + defaultImageURL + iconClosed + "" width="16" height="16" align="absmiddle" alt="Haz click para abrir esta carpeta" border="0" /></a>&nbsp;<a href="" + children[currentIndex]. Url + "" target="<%=targetFrame%>" id="_" + children[currentIndex]. Dbid + "" onclick="parent. Setthestate("_" + children[currentIndex]. Dbid + "","" + children[currentIndex]. Url +"");return false">" + children[currentIndex]. Name + "&nbsp;</a><br /> ")
}else {
outputFrame. Write("<a href="javascript:top. ToggleFolder("" + children[currentIndex]. Id + "",0)" onmouseover="window. Status="Haz click para cerrar esta carpeta"; return true"><img src="" + defaultImageURL + "img-minus-end-" + structureStyle + ". Gif" width="19" height="16" alt="Haz click para cerrar esta carpeta" align="texttop" border="0" />");
outputFrame. Write("<img src="" + defaultImageURL + iconOpen + "" width="16" height="16" align="absmiddle" alt="Haz click para cerrar esta carpeta" border="0" /></a>&nbsp;<a href="" + children[currentIndex]. Url + "" target="<%=targetFrame%>" id="_" + children[currentIndex]. Dbid + "" onclick="parent. Setthestate("_" + children[currentIndex]. Dbid + "","" + children[currentIndex]. Url +"");return false">" + children[currentIndex]. Name + "&nbsp;</a><br /> ");
newStructure = newStructure + "<img src="" + defaultImageURL + "img-blank. Gif" width="19" height="16" align="texttop" />";
drawBranch(children[currentIndex]. Id,newStructure);
}
}
}
currentIndex++;
}
}
function toggleFolder(id,status) {
var nodeIndex = indexOfNode(id);
treeData[nodeIndex]. Open = status;
timeOutId = setTimeout("drawTree()",100)
}
function indexOfNode(id) {
var currentIndex = 1;
while (currentIndex <= treeData. Length) {
if (treeData[currentIndex]. Type == "root") || (treeData[currentIndex]. Type == "folder")) {
if (treeData[currentIndex]. Id == id) {return currentIndex}}
currentIndex++}
return -1
}
function extractChildrenOf(node) {
var children = new Collection();
var currentIndex = 1;
while (currentIndex <= treeData. Length) {
if (treeData[currentIndex]. Type == "folder") || (treeData[currentIndex]. Type == "link")) {
if (treeData[currentIndex]. Parent == node) {
children. Add(treeData[currentIndex])}}
currentIndex++}
return children
}
function Collection() {
this. Length = 0;
this. Add = add;
return this
}
function add(object) {
this. Length++;
this[this. Length] = object
}
function RootNode(id,name,url,target,icon) {
this. Id = id;
this. Name = name;
this. Url = url;
this. Target = target;
this. Icon = icon;
this. Type = "root";
return this
}
function FolderNode(id,parent,name,iconClosed,iconOpen,url,dbid) {
this. Id = id;
this. Parent = parent;
this. Name = name;
this. IconClosed = iconClosed;
this. IconOpen = iconOpen;
this. Url = url;
this. Dbid = dbid;
this. Type = "folder";
this. Open = 0;
return this
}
function LinkNode(parent,name,url,target,icon,dbid) {
this. Parent = parent;
this. Name = name;
this. Url = url;
this. Target = target;
this. Icon = icon;
this. Type = "link";
this. Dbid = dbid;
return this
}
function loadData() {
treeData = new Collection();
treeData. Add(new RootNode("root","Isis","page. Asp? Id=","",""));
<%=Mainjscript%>
structureStyle = 0;
backgroundColor = "#FFFFFF";
textColor = "#000000";
linkColor = "#0000AA";
aLinkColor = "#FF0000";
vLinkColor = "#880088";
backgroundImage = "";
defaultTargetFrame = "pageFrame";
defaultImageURL = "images/";
defaultLinkIcon = "img-page-globe. Gif";
omenTreeFont = "MS Sans Serif,Arial,Helvetica";
omenTreeFontSize = 1;
prefixHTML = "";
suffixHTML = "";
}
var oldsel = "";
function setthestate(element, url){
var obj = treeFrame.document.getElementsByTagName("A");
var j = treeFrame.document.getElementsByTagName("A"). Length;
for (i=0; i < j; i++){
if (obj . TagName == "A"){
obj . ClassName = "A_desel";
}
}
var tobj = treeFrame.document.getElementById(element);
tobj. ClassName = "A_sel";
oldsel = element;
window. Open(url, "pageFrame");
return false;
}
Angeles Sebastián
Arquitectura - 5º politecnica de madrid
Escrito por Angeles Sebastián
el 15/10/2009

Buenos días,

En la consulta tienes WHERE parent=" & parent & ", esto sería para parent numérico, si parent es de texto tendrías que poner: WHERE parent='" & parent & "' , es decir meterlo entre comillas simples.

Saludos, angeles