0
樣品字符串:不知道如何將這個JSON對象進行排序的jQuery/JavaScript的
var output = {
"myservices":[
{"name":"oozie", "hostidn": "1", "details":"failed process health monitor....", "currstatus":"Warning", "currstatusclass":"warning"},
{"name":"oozie", "hostidn": "2", "details":"failed process health monitor....", "currstatus":"Warning", "currstatusclass":"warning"},
{"name":"oozie", "hostidn": "3", "details":"failed process health monitor....", "currstatus":"Warning", "currstatusclass":"warning"},
{"name":"oozie", "hostidn": "4", "details":"failed process health monitor....", "currstatus":"Warning", "currstatusclass":"warning"},
{"name":"oozie", "hostidn": "5", "details":"failed process health monitor....", "currstatus":"Warning", "currstatusclass":"warning"},
{"name":"single-namenode", "hostidn": "2", "details":"failed process health monitor....", "currstatus":"Warning", "currstatusclass":"warning"}
]};
在做我的餅乾傑克嘗試。
function sortJSONresultsByHost(a,b)
{
var objectIDA = parseInt(a.hostidn, 10)
var objectIDB = parseInt(b.hostidn, 10)
if(objectIDA === objectIDB)
{
return 0;
}
return objectIDA > objectIDB ? 1 : -1;
}
output.myservices.sort(sortJSONresultsByHost);
我其實需要弄清楚如何排序這種不同的方式。如hostidn,按名稱,由currstatusclass。但我無法弄清楚最好的辦法。有沒有辦法讓一個功能可以做任何選擇,或者我需要做一套基於我想要做的功能,如果兩個方法如何?我的上面沒有爲我工作。
不要假設在一個不同的主題與相同的對象數據,你會知道我怎麼能得到最高的hostidn值嗎? – chris
@chris不理解您的評論.. – wong2