当我们键入多动态数组的静态内容和创建数组的数组时有什么区别
如果我使用下面的静态值,那么我的代码工作正常:
ohlc = [[090300, 25.75, 25.75, 25.75, 25.75],
[090400, 25.75, 25.75, 25.75, 25.75],
[090700, 25.73, 25.73, 25.73, 25.73],
[091300, 25.76, 25.76, 25.76, 25.76]];
但是如果我使用下面的代码,那么我的代码就无法工作,
var labels = xmlDoc.getElementsByTagName('node');
arr = new Array();
var str = '';
for (i = 0; i < labels.length; i++) {
if (labels[i].childNodes.length >= 9) {
arr[i] = new Array(5);
arr[i][0] = labels[i].childNodes[1].textContent;
arr[i][1] = labels[i].childNodes[3].textContent;
arr[i][2] = labels[i].childNodes[5].textContent;
arr[i][3] = labels[i].childNodes[7].textContent;
arr[i][4] = labels[i].childNodes[9].textContent;
}
}
即使我在 arr 上循环并警告该值,也比我复制了数组的值并粘贴静态及其工作.. 我正在读取 xml 并创建一个 2D 数组以在 jqphot 中显示图表。 请给我一个线索
if i am using below static values than my code is working fine:
ohlc = [[090300, 25.75, 25.75, 25.75, 25.75],
[090400, 25.75, 25.75, 25.75, 25.75],
[090700, 25.73, 25.73, 25.73, 25.73],
[091300, 25.76, 25.76, 25.76, 25.76]];
but if i am using below code than my code is not working
var labels = xmlDoc.getElementsByTagName('node');
arr = new Array();
var str = '';
for (i = 0; i < labels.length; i++) {
if (labels[i].childNodes.length >= 9) {
arr[i] = new Array(5);
arr[i][0] = labels[i].childNodes[1].textContent;
arr[i][1] = labels[i].childNodes[3].textContent;
arr[i][2] = labels[i].childNodes[5].textContent;
arr[i][3] = labels[i].childNodes[7].textContent;
arr[i][4] = labels[i].childNodes[9].textContent;
}
}
even i did loop on arr and alert the value than i have copyed value of array and pasted static and its working..
i am reading xml and creating an 2D array to show chart in jqphot.
please give me a clue for this
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要将文本字符串转换为数字。您可以使用
parseFloat
函数:You probably need to convert the text strings to numbers. You would use the
parseFloat
function for that: