[英]Alphabetically sort JQM list view?
i have a JSON in forma key - value: 我在格式键中有一个JSON-值:
{
"535826": "Adamov",
"536156": "Bečice",
"544272": "Borek",
"544281": "Borovany",
"535681": "Borovnice",
"544299": "Boršov nad Vltavou",
"535401": "Bošilec",
"551490": "Branišov",
"536059": "Břehov"
}
If i display source code of this writeout is everything sorted as above, aplhabeticaly. 如果我显示此写出的源代码是按上述方式排序的所有内容,则为ablhabeticaly。
Problem is, if I used jQuery.ajax 问题是,如果我使用jQuery.ajax
In this case are returned values sorted ordered by ID, for example 536059 在这种情况下,返回值按ID排序,例如536059
I writing on Jquery mobile list, ad so i cannot use sort method like 我在Jquery移动列表上写广告,所以我不能使用排序方法
//SORT UNORDERED LIST - NOT USED
function sortUnorderedList(ul, sortDescending) {
if(typeof ul == "string")
ul = document.getElementById(ul);
// Idiot-proof, remove if you want
if(!ul) {
alert("The UL object is null!");
return;
}
// Get the list items and setup an array for sorting
var lis = ul.getElementsByTagName("LI");
var vals = [];
// Populate the array
for(var i = 0, l = lis.length; i < l; i++)
vals.push(lis[i].innerHTML);
// Sort it
vals.sort();
// Sometimes you gotta DESC
if(sortDescending)
vals.reverse();
// Change the list on the page
for(var i = 0, l = lis.length; i < l; i++)
lis[i].innerHTML = vals[i];
}
Exist any easy solutions for this? 是否存在任何简单的解决方案?
Many thanks for any help. 非常感谢您的帮助。
The problem with the map is that it is inherently unsorted. 地图的问题在于它本质上是未排序的。 Do you have control over the source?
您可以控制来源吗? You could generate a list of key/value pairs, in which the order would be maintained:
您可以生成一个键/值对的列表,其中的顺序将得到维护:
[{"535826": "Adamov"},
{"536156": "Bečice"},
{"544272": "Borek"},
{"544281": "Borovany"},
{"535681": "Borovnice"},
{"544299": "Boršov nad Vltavou"},
{"535401": "Bošilec"},
{"551490": "Branišov"},
{"536059": "Břehov"}]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.