2017-10-20 85 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中的每個項目都是具有項目值的對象(如果您想顯示一個漂亮的字符串),一個包含該項目顏色名稱的數組,以及另一個包含該項目顏色代碼的數組。

我希望這可以幫助你。

祝你好運。