我有這樣Javascript或JQuery的JSON對象分組
[
{"attributes":{"SHAPELEN":26.2293318917963,"CITYID":2061}},
{"attributes":{"SHAPELEN":16.9352548253636,"CITYID":2062}},
{"attributes":{"SHAPELEN":22.101151804600597,"CITYID":2063}},
{"attributes":{"SHAPELEN":22.8809188858315,"CITYID":2061}},
{"attributes":{"SHAPELEN":18.6906905910402,"CITYID":2063}},
{"attributes":{"SHAPELEN":31.322932493622,"CITYID":2062}},
{"attributes":{"SHAPELEN":10.5580020747299,"CITYID":2063}},
]
一個JSON數據,並通過我和CITYID總和SHAPELENs這樣想這組數據。
[
{CITYID:2061, TOTAL=49.1},
{CITYID:2062, TOTAL=47.2},
{CITYID:2063, TOTAL=51,34}
]
我創建了一個javascript函數,但沒有工作,我想。
function gropData(data) {
var features = data.features;
var cities = [];
$.each(features, function (index, item) {
// **if cities not include item, add in cities. But if not working here**
if (!$.inArray(item.attributes, cities)) {
cities.push(item.attributes);
}
});
}
有沒有你看到的解答?
這是什麼'$ inArray(item.attributes,市)'該怎麼辦!?另外'$ .inArray'返回一個索引,所以如果你想檢查重複的,你應該做的'$ .inArray == -1' –