我有兩個json數組。 EXP:推動元素正在改變json數據中的以前的元素
$scope.arr1 = [
{ "id": 1, "first_name": "Philip", "last_name": "Kim", "email": "[email protected]", "country": "Indonesia", "ip_address": "29.107.35.8" },
{ "id": 2, "first_name": "Judith", "last_name": "Austin", "email": "[email protected]", "country": "China", "ip_address": "173.65.94.30" },
{ "id": 3, "first_name": "Julie", "last_name": "Wells", "email": "[email protected]", "country": "Finland", "ip_address": "9.100.80.145" },
{ "id": 4, "first_name": "Gloria", "last_name": "Greene", "email": "[email protected]", "country": "Indonesia", "ip_address": "69.115.85.157" },
{ "id": 5, "first_name": "Andrea", "last_name": "Greene", "email": "[email protected]", "country": "Russia", "ip_address": "128.72.13.52" }]
$scope.arr2=[];
和欲推ARR1的元素根據一些條件由字段ARR2字段。
var object;
var temp = {};
for (var i in $scope.arr1) {
object = $scope.arr1[i];
for (var property in object) {
temp2 = object.id + '_' + property;
if ($scope.someOtherData.indexOf("unhighlighted") != -1) {
temp[property] = "";
}
else {
temp[property] = object[property];
}
}
$scope.arr2.push(temp);
}
我的第一個問題: 先將溫度推到arr2好。但是,當我推第二或更多arr2中的所有元素都變成最後的臨時值。我可以修復這個問題嗎?
我的第二個問題是:我沒有將$$ hashKey屬性添加到arr1。但它是自發發生的。 我該如何預防?
$$ hashKey是私有角度變量。 –