0
我有以下數據結構:陣列搜索不工作
var map_neighbours = [{
"Alaska": ["UstKamchatsk", "Yukon"]
}, {
"Algeria": ["Chad", "Egypt", "SierraLeone", "Spain"]
}, {
"AntarticWildlifeTerritory": ["AustralianAntarticTerritory", "SouthAfricanAntarticTerritory"]
}, .....]
用戶通過頁面選擇一個區域,我通過這個結構要循環,找到區域,然後通過分圈區域(在相應位置)。
因此,例如,對於Algeria
我想要"Chad", "Egypt", "SierraLeone", "Spain"
一個循環出來。
我曾嘗試的這沒有成功幾個變化(region
由用戶如上所述提供):
var neighbourArray = map_neighbours[region];
$.each(neighbourArray, function(idx, val) {
console.log("Neighbours= " + neighbourArray[region][idx]);
});
或
$.each(map_neighbours, function(outer, val) {
if (map_neighbours[outer] == region) {
neighbourArray = (map_neighbours[outer][]);
$.each(neighbourArray, function(inner, val) {
console.log("Neighbours= " + neighbourArray[outer][inner]);
});
);
};
感謝您的任何建議。
是''=>'應該在那裏,還是應該是':'? –