如何在angualrjs中扩展两个数组?

时间:2016-06-30 08:58:20

标签: angularjs

我想合并2个数组。阵列来自两个不同的Apis。我使用concat和extend但是没有正确使用。

String base64data = response.getString("data");
                byte[] data = Base64.decode(base64data,
                        Base64.DEFAULT);
                String decoded_text= new String(data, "UTF-8");
                decoded_text=decoded_text.replaceAll("[\n\r]", "WRAP");
                decoded_text=decoded_text.replaceAll("WRAP","\n\r");
                textview.setText(decoded_text);

控制台中$ scope.notifications1的响应

$scope.notifications1=ComboService.getcomboNote();
console.log($scope.notifications1)
$scope.notifications2=ComboService.getofferNote();
console.log($scope.notifications2)

控制台中$ scope.notifications1的响应

Array[1]
0:Resource
__v:0
_id:"57564ecea635e6695238cebc"
createdAt:"2016-06-07T04:34:22.235Z"
defaultmainprice:250
defaultofferprice:251
isDeleted:false
itemcode:"C101"
itemdescription:"Combo123"
itemname:"Combo123"
itemstock:0
itemtype:"combos"
modifiedAt:"2016-06-07T04:34:22.235Z"
__proto__:Object
$promise:Promise
$resolved:true
length:1

我像这样使用concat

Array[1]
0:Resource
__v:0
_id:"5774b69781478fbaee51cdbf"
createdAt:"2016-06-30T06:05:11.619Z"
defaultmainprice:10
defaultofferprice:5
isDeleted:false
itemcode:"10000111"
itemdescription:"Offer1"
itemname:"Offer1"
itemstock:0
itemtype:
"offers"
modifiedAt:"2016-06-30T06:05:11.619Z"
__proto__:Object
$promise:Promise
$resolved:true
length:1

我使用像这样的扩展

$scope.notifications = $scope.notifications1.concat($scope.notifications2)

但没有得到适当的。请帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

对于深层复制,您需要使用merge