2009-08-20 28 views
0

我本地化菜单,我想声明的数组中的方式分配给一个对象属性:如果分配现有的JavaScript数组的属性在对象符号

var menuListLocal=["Home","Play","Options","Exit"]; 

var menu_Controller={ 
_menuList: menuListLocal, 
// .... // 
} 

对不起实在是太明显了。

谢谢。

+1

从您的文章中不清楚您的问题是什么。 – 2009-08-20 16:11:28

+3

Uuhm这应该工作?唯一的问题,你应该删除最后一个,只使用一个,分隔属性不在最后... – Ropstah 2009-08-20 16:13:03

+0

我第二@jeffamaphone,不知道什么问题是... – localshred 2009-08-20 16:15:07

回答

3

你应该有什么工作,记住ropstah的评论。

var menuListLocal=["Home","Play","Options","Exit"]; 

var menu_Controller={ 
_menuList: menuListLocal, 
_other: 'Something' 
}; 

用法示例:

var home = menuListLocal._menuList[0]; 
0

奇怪的是,它不工作。如果John的回答没有为您清理它,请尝试在menu_Controller的init()方法中明确地设置它:

var menuListLocal=["Home","Play","Options","Exit"]; 

var menu_Controller={ 
    _menuList: null, 

    init : function(){ 
     menu_Controller._menuList = menuListLocal; 
    } 

} 
menu_Controller.init(); 
相关问题