我有一個JSON JS對象。我需要用ng-repeat來複制這些數據。問題是數組的基本密鑰正在改變。我會解決這個問題。這個JSON將嵌套NG重複顯示帶有隨機密鑰的JSON AngularJS
var JSON = {
"DK-App": [{
"_id": 1056,
"thread_id": 328,
"address": "DK-App",
"date": 1507470152962,
"date_sent": 1507470093000,
"protocol": 0,
"read": 0,
"status": -1,
"type": 1,
"reply_path_present": 0,
"locked": 0,
"sub_id": 2,
"phone_id": 1,
"error_code": 0,
"creator": "com.android.mms",
"seen": 0,
"priority": -1,
"oppo_drafts": 1,
"sim_id": -1,
"oppo_mass": 0,
"oppo_timer": 0,
"oppo_groupaddress": "DK-App",
"oppo_collected": 0,
"oppo_sub_date": 1507470093000,
"oppo_service_message_sms_type": 0,
"deleted": 0,
"sync_state": 0,
"oppo_sms_type": 0,
"$$hashKey": "object:4"
}, {
"_id": 1028,
"thread_id": 328,
"address": "DK-App",
"date": 1507360655265,
"date_sent": 1507360594000,
"protocol": 0,
"read": 0,
"status": -1,
"type": 1,
"reply_path_present": 0,
"locked": 0,
"sub_id": 2,
"phone_id": 1,
"error_code": 0,
"creator": "com.android.mms",
"seen": 1,
"priority": -1,
"oppo_drafts": 1,
"sim_id": -1,
"oppo_mass": 0,
"oppo_timer": 0,
"oppo_groupaddress": "DK-App",
"oppo_collected": 0,
"oppo_sub_date": 1507360594000,
"oppo_service_message_sms_type": 0,
"deleted": 0,
"sync_state": 0,
"oppo_sms_type": 0,
"$$hashKey": "object:27"
}, {
"_id": 985,
"thread_id": 328,
"address": "DK-App",
"date": 1507198047122,
"date_sent": 1507197980000,
"protocol": 0,
"read": 0,
"status": -1,
"type": 1,
"reply_path_present": 0,
"locked": 0,
"sub_id": 2,
"phone_id": 1,
"error_code": 0,
"creator": "com.android.mms",
"seen": 1,
"priority": -1,
"oppo_drafts": 1,
"sim_id": -1,
"oppo_mass": 0,
"oppo_timer": 0,
"oppo_groupaddress": "DK-App",
"oppo_collected": 0,
"oppo_sub_date": 1507197980000,
"oppo_service_message_sms_type": 0,
"deleted": 0,
"sync_state": 0,
"oppo_sms_type": 0,
"$$hashKey": "object:45"
}, {
"_id": 977,
"thread_id": 328,
"address": "DK-App",
"date": 1507179236636,
"date_sent": 0,
"read": 0,
"status": -1,
"type": 1,
"locked": 0,
"sub_id": 2,
"phone_id": 1,
"error_code": 0,
"creator": "com.android.mms",
"seen": 1,
"priority": -1,
"oppo_drafts": 1,
"sim_id": -1,
"oppo_mass": 0,
"oppo_timer": 0,
"oppo_collected": 0,
"oppo_service_message_sms_type": 0,
"deleted": 0,
"sync_state": 0,
"oppo_sms_type": 0,
"$$hashKey": "object:48"
}],
"BZ-FPANDA": [{
"_id": 1055,
"thread_id": 96,
"address": "BZ-FPANDA",
"date": 1507469661223,
"date_sent": 1507469657000,
"protocol": 0,
"read": 0,
"status": -1,
"type": 1,
"reply_path_present": 0,
"locked": 0,
"sub_id": 1,
"phone_id": 0,
"error_code": 0,
"creator": "com.android.mms",
"seen": 0,
"priority": -1,
"oppo_drafts": 1,
"sim_id": -1,
"oppo_mass": 0,
"oppo_timer": 0,
"oppo_groupaddress": "BZ-FPANDA",
"oppo_collected": 0,
"oppo_sub_date": 1507469657000,
"oppo_service_message_sms_type": 0,
"deleted": 0,
"sync_state": 0,
"oppo_sms_type": 0,
"$$hashKey": "object:5"
}, {
"_id": 930,
"thread_id": 96,
"address": "BZ-FPANDA",
"date": 1506925028930,
"date_sent": 1506925025000,
"protocol": 0,
"read": 0,
"status": -1,
"type": 1,
"reply_path_present": 0,
"locked": 0,
"sub_id": 1,
"phone_id": 0,
"error_code": 0,
"creator": "com.android.mms",
"seen": 1,
"priority": -1,
"oppo_drafts": 1,
"sim_id": -1,
"oppo_mass": 0,
"oppo_timer": 0,
"oppo_groupaddress": "BZ-FPANDA",
"oppo_collected": 0,
"oppo_sub_date": 1506925025000,
"oppo_service_message_sms_type": 0,
"deleted": 0,
"sync_state": 0,
"oppo_sms_type": 0,
"$$hashKey": "object:56"
}]
}
這個JSON需要爲每個陣列創建列表。然而每個陣列的鍵是不同的。納克重複不與
ng-repeat="j in JSON"
在此之前的工作我試圖通過推動基於關鍵只
var result = {};
data.forEach(function(item) {
if (!result[item.address])
result[item.address] = [item];
else
result[item.address].push(item);
});
現在我得到一個JSON與「鑰匙」公共N正常化這個數組列表包含陣列。原始的JSON Lools這樣的
我試圖推動普通對象基於關鍵address
。 我需要在JSON變量中訪問「DK-App」和「BZ-FPANDA」,並且需要在「DK-APP」和「BZ-FPANDA」中迭代數組。請注意,這些「DK-APP」和「BZ-FPANDA」都是從後端編程的,並且有這樣的巨大列表。問題的陳述是我如何獲得使用JS的數組,以便我可以迭代它
我需要訪問 「DK-應用程序」 和 「BZ-FPANDA」 在JSON變量,需要遍歷這兩個 「DK-APP」 和 「BZ-FPANDA」 裏面的數組。請注意,這些「DK-APP」和「BZ-FPANDA」都是從後端編程的,並且有這樣的巨大列表。問題聲明是如何獲得使用JS的數組,以便我可以遍歷它 – Siddharth