2017-10-20 70 views
-2

我有一个问题调用我的对象内的数组。
而且我有一个数组(在对象内)称为:items
而且我还有其它的阵列,如“name_of_the_item_color_names”和“name_of_the_item_color_codes”(只是要清楚,name_of_the_item是一个占位符,它的阵列items内的一个值)
反正我不知道是否有访问它们的方式,使用items以及_color_names_color_codes的值中的一个。
顺便说一句,我知道有像[additions_colorizing.items[i]][total]的方法,但我不知道我是否可以添加额外的部件(再次,_color_names_color_codes

下面是一个例子,以部分代码: 访问对象内的数组

var additions_colorizing = { 
 
     items: ['', 
 
       'long_hair', 
 
       'fancy_hair', 
 
       'boys_hair', 
 
       'cadence_hair', 
 
       'mask', 
 
       'viking_helmet', 
 
       'hard_hat', 
 
       'nose', 
 
       'mask', 
 
       'snowtuber', 
 
       'normal_headphones', 
 
       'classic_headphones', 
 
       'party_headphones', 
 
       'cpi_party_hat', 
 
       'cp_party_hat', 
 
       'fairy_wings' 
 
       ], 
 
     mask_color_names: ['', 
 
           'yellow', 
 
           'orange', 
 
           'peach', 
 
           'red', 
 
           'mint', 
 
           'green', 
 
           'olive_green', 
 
           'dark_green', 
 
           'blue', 
 
           'dark_blue', 
 
           'azure', 
 
           'azure2', 
 
           'light_pink', 
 
           'pink', 
 
           'purple', 
 
           'dark_purple', 
 
           'white', 
 
           'grey', 
 
           'black', 
 
           'brown' 
 
          ], 
 
     mask_color_codes: ['', 
 
         '#FFF000', 
 
         '#FF8400', 
 
         '#FF894E', 
 
         '#EB0505', 
 
         '#00FF59', 
 
         '#4DCB09', 
 
         '#659B20', 
 
         '#19750D', 
 
         '#0486C8', 
 
         '#203D93', 
 
         '#53C5FF', 
 
         '#1BB3AE', 
 
         '#F862D0', 
 
         '#FD009B', 
 
         '#CC10E8', 
 
         '#680F93', 
 
         '#FFFFFF', 
 
         '#797979', 
 
         '#000000', 
 
         '#BA6C08' 
 
      ]} 
 
      //there's more... but I deleted 90% of it ^^

另外

var item = additions_colorizing.items[5]; //This will get the 'mask' value 
var item_color_names = additions_colorizing[item + '_color_names']; //This gets the 'mask_color_names' array 
var item_color_codes = additions_colorizing[item + '_color_codes']; //This gets the 'mask_color_codes' array 

,我:

+0

请附上您的代码。 –

+0

如果您提供了对象结构的片段,并且可能是您迄今为止尝试过的代码块,可能会有所帮助。 – scrappedcola

+0

请明确你的答案:我不明白 – PhilMaGeo

回答

0

您可以访问的变量你想这样除了使用如此多的数组(对于additions_colorizing.items中的每个项目使用2个数组),您还可以使用继承/对象结构,其中additions_colorizing.items中的每个项目都是具有项目值的对象(如果您想显示一个漂亮的字符串),一个包含该项目颜色名称的数组,以及另一个包含该项目颜色代码的数组。

我希望这可以帮助你。

祝你好运。