所以,我已經有了一個巨大數組是這樣的:多維名選擇
var enemy = {
'level1' : {
creature :
{
creature_name : {
'Goblin' : {
info: {
'c_name' : 'Goblin',
'HP' : '20',
'damage' : '3',
'loot' : [
{name: 'a wooden sword' , item: 'weapon' , value: 2},
{name: 'a golden necklace', item: 'amulet' , value: 1},
{name: 'a pair of boots' , item: 'boots' , value: 1},
{name: 'some cloth legs' , item: 'legs' , value: 3},
{name: 'a cloth helmet' , item: 'helm' , value: 2}
]
}
},
'Cow' : {
info: {
'c_name' : 'Cow',
'HP' : '10',
'damage' : '1',
'loot' : [
{name: 'a wooden sword' , item: 'weapon' , value: 2},
{name: 'a golden necklace', item: 'amulet' , value: 1},
{name: 'a pair of boots' , item: 'boots' , value: 1},
{name: 'a cloth helmet' , item: 'helm' , value: 2}
]
}
},
'dragon' : {
info: {
'c_name' : 'Cow',
'HP' : '300',
'damage' : '300',
'loot' : [
{name: 'an almighty dragon sword' , item: 'weapon' , value: 200},
{name: 'a dragon tooth', item: 'amulet' , value: 30},
{name: 'a pair of dragon boots' , item: 'boots' , value: 60},
{name: 'a dragon helmet' , item: 'helm' , value: 60}
]
}
},
}
},
},
'level2' : {
'skelleton' : {
'HP' : '40',
'damage' : '5',
'loot' : [
{name: 'a bone' , item: 'weapon' , value: 1},
{name: 'a warriors helmet' , item: 'helm' , value: 4}
]
}
}
};
,當我選擇生物我想我需要調用它像這樣:
enemy.level1.creature.creature_name.dragon.info.c_name
現在我想能夠通過input box
或類似的東西選擇一個敵人。 但我無法弄清楚如何我中插入enemy.level1.creature.creature_name.dragon.info.c_name
該值我試着用enemy.level1.creature.creature_name.+ input_value + .info.c_name
但是,這似乎並沒有工作。必須是一個簡單的解決方案呢?
'enemy.level1.creature.creature_name [input_value] .info.c_name' – Pointy
謝謝!會嘗試一下:) – GetOn
'enemy.level1.creature.creature_name [input_value] .info.c_name' – vaso123