【发布时间】:2020-04-28 04:18:32
【问题描述】:
我有一个国家到州的动态 JSON 地图。前任。 {"Canada":["Ontario","Quebec","Alberta"],"USA":["Michigan","Maine","New Hampshire"]}
我知道所选的国家/地区名称。
问题:如何从地图中获取所选国家名称的州列表并遍历值?
<script>
function onChangeCountry() {
var selectedCountry = $('#country').find(":selected").text();
alert("010 selectedCountry = "+ selectedCountry); // <<-- this gets me the selected country, works fine
var jsonMapCountryToStates = ${jsonMapCountryToStates};
alert("020 JSON.stringify(jsonMapCountryToStates) = "+JSON.stringify(jsonMapCountryToStates)); // <-- this shows me the whole map
// how do I iterate through the list of states for 'selectedCountry' ?
}
</script>
【问题讨论】:
标签: javascript json