Hi All,
I am facing a problem with eval function.
My requirement is to plot a chart (tree type) on the html page from xml.
I am using the jsTreeGraph to do the same. This needs multidimension array as an input with each level adding to each dimension of the array.
To be clear, if we have a 4 level tree, then the array should be 3 dimensional array. Please download the jsTreeGraph for the built in example (as I am new to this forum and I don’t know how to attach the files here ).
Returning to my problem, My code is shown below :
function myLoading() {
var xmlDoc=new ActiveXObject(“Microsoft.XMLDOM”);
xmlDoc.async=“false”;
xmlDoc.load(“http://localhost:8080/SayIt/MyData.xml”);
var len = xmlDoc.getElementsByTagName("Account").length;
var depth = xmlDoc.getElementsByTagName("Level")[len-1].childNodes[0].nodeValue;
var rootNode = { Content:xmlDoc.getElementsByTagName("Account")[0].childNodes[0].nodeValue, Nodes:[] };
for (var i=1; i < len ; i++) {
var str= new String();
var myVal = xmlDoc.getElementsByTagName("Account")[i].childNodes[0].nodeValue;
alert('For My Val '+ myVal);
str='rootNode'+fnGetVarName(xmlDoc.getElementsByTagName("Account")[i].childNodes[0].nodeValue, xmlDoc, xmlDoc.getElementsByTagName("Level")[i].childNodes[0].nodeValue,str)+'.Content = '+ myVal;
str = str.slice(0,-1);
alert(str);
eval(str);
}
a = 'varname';
str = a+' = '+'123';
eval(str);
alert(str);
alert(a);
alert(varname);
rootNode.Nodes[0] = { Content: "Fisrt Child" };
rootNode.Nodes[1] = { Content: "Second Child", ToolTip: "My Tooltip" };
var container = document.getElementById("dvTreeContainer");
DrawTree({
Container: container,
RootNode: rootNode
});
}
function fnGetVarName(child, xmlDocLoc, currLevel, dispVar){
if (dispVar == undefined) {
dispVar = ’ ';
}
var ind=0;
if (currLevel > 1) {
for (var i = 0; i < xmlDocLoc.getElementsByTagName("Account").length; i++) {
if (xmlDocLoc.getElementsByTagName("Level")[i].childNodes[0].nodeValue == currLevel) {
ind++;
if (xmlDocLoc.getElementsByTagName("Account")[i].childNodes[0].nodeValue == child) {
if (currLevel == 2) break;
dispVar=fnGetVarName(xmlDocLoc.getElementsByTagName("Parent")[i].childNodes[0].nodeValue, xmlDocLoc, currLevel-1, dispVar);
break;
}
}
}
}
dispVar = dispVar+'\\.Nodes\\['+(ind - 1)+'\\]';
return (dispVar);
}
The function myLoading() is called when the html body is loaded (onLoad property, for testing).
When I try to dynamically set it, eval is failing.
I am quiet new to eval function and the way it evaluates the expression.
Please check this and help me in constructing my multidimension array with indexes dynamically for plotting it.
PS : Kindly excuse me if the formatting of the code doesn’t come along per guidelines of the forum.
If needed anything please mail me @ raviraj636@gmail.com