我正在尝试访问一个简单的嵌套数组,这样做:
var currMenu = 1;
while ( currMenu < menu.length ) {
alert(currMenu);
alert(menu[0][currMenu].text);
currMenu++;
}
尽管警报抛出了正确的值,但我在 firebug 上收到此错误:TypeError: menu[0][currMenu] is undefined。
怎么了?
谢谢!
编辑:对不起,我很着急,这里有“菜单”结构:
menu[0] = new Array();
menu[0][0] = new Menu(false, '', 15, 50, 20, '','' , 'navlink', 'navlink');
menu[0][1] = new Item('someText', '#', '', 100, 10, 1);
和对象项目:
function Item(text, href, frame, length, spacing, target) {
this.text = text;
if (href == '#') {
this.href = '#';
} else if (href.indexOf('http') == 0) {
this.href = href;
} else this.href = href;
this.frame = frame;
this.length = length;
this.spacing = spacing;
this.target = target;
// Reference to the object's style properties (set later).
this.ref = null;
this.showLoadingBar = false;
}