Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/441.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将现有javascript数组分配给对象表示法中的属性_Javascript_Json - Fatal编程技术网

将现有javascript数组分配给对象表示法中的属性

将现有javascript数组分配给对象表示法中的属性,javascript,json,Javascript,Json,我正在本地化一个菜单,并希望以这种方式将声明的数组分配给对象属性: var menuListLocal=["Home","Play","Options","Exit"]; var menu_Controller={ _menuList: menuListLocal, // .... // } 如果太明显的话,我很抱歉 谢谢。记住罗普斯塔的评论,你所拥有的应该有用 var menuListLocal=["Home","Play","Options","Exit"]; var menu_C

我正在本地化一个菜单,并希望以这种方式将声明的数组分配给对象属性:

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

var menu_Controller={
 _menuList: menuListLocal,
 // .... //
}
如果太明显的话,我很抱歉


谢谢。

记住罗普斯塔的评论,你所拥有的应该有用

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

var menu_Controller={
 _menuList: menuListLocal,
 _other: 'Something'
};
使用示例:

var home = menuListLocal._menuList[0];

记住罗普斯塔的评论,你所拥有的应该有用

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

var menu_Controller={
 _menuList: menuListLocal,
 _other: 'Something'
};
使用示例:

var home = menuListLocal._menuList[0];

奇怪的是它不起作用。如果John的答案无法为您澄清,请尝试在菜单\控制器上的init()方法中显式设置它:

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

var menu_Controller={
   _menuList: null,

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

}
menu_Controller.init();

奇怪的是它不起作用。如果John的答案无法为您澄清,请尝试在菜单\控制器上的init()方法中显式设置它:

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

var menu_Controller={
   _menuList: null,

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

}
menu_Controller.init();

你的帖子不清楚你的问题是什么。嗯,这应该行吗?唯一的一件事,你应该删除最后一个,只使用一个,来分开属性,而不是在最后…我第二个@jeffamaphone,不确定问题是什么…你的帖子不清楚你的问题是什么。嗯,这应该行得通吗?唯一的一件事,你应该删除最后一个,只使用一个,以分离属性,而不是在结尾…我第二个@jeffamaphone,不确定问题是什么…使用示例不应该是:
var home=menu\u Controller.\u menuList[0]
?使用示例不应该是:
var home=menu\u Controller.\u menuList[0]