【发布时间】:2017-07-18 17:40:06
【问题描述】:
我有一个从 JSON 数组中提取国家/地区列表的函数
function regionPlanOutput(networkGroupId) {
document.getElementById("country_list").innerHTML = "";
jQuery.ajax({
type: 'GET'
, url: regionApiURL + '/api/v4/networkGroups/' + networkGroupId + '/countries?count=500'
, dataType: 'json'
, success: function (networkGroup) {
jQuery.each(networkGroup.countryList, function (i, countryList) {
var countryName = countryList.name;
var flag = countryList.logoUrl;
var countrycontent = '<li>' + countryName + '</li>';
console.log(countrycontent)
jQuery(countrycontent).appendTo("#country_list");
});
}
});
}
目前它只是按照从数组中提取它们的顺序打印列表,如何根据变量 countryName 按字母顺序对输出进行排序?
【问题讨论】:
-
你能包括输出 JSON 的样子吗?
-
请注意,当您到达
success时,networkGroup参数已经是一个 JavaScript 对象,而不是 JSON。 JSON 是一种字符串格式,因此谈论 JSON 数组是不好的术语。
标签: javascript arrays json sorting object