Angularjs将一个对象数组的内容添加到另一个对象数组中

时间:2016-11-25 20:52:34

标签: angularjs json

我有两个变量:

第一个:

 studentSearchCriteria1=   {"studentList1":"key":"firstName","match":$scope.firstName,  "value":$scope.studentSearchCriteria.studentfName},],"searchUserInformationKey": [ "",],"start": 0}

和第二个:

 var studentSearchCriteria1 = {"studentList2":[{"key":"lastName","match":$scope.firstName,"value":$scope.studentSearchCriteria.studentlName},],"searchUserInformationKey":["",],"start": 0}

我想将一个数组的内容添加到另一个数组,结果应为:

{"studentList1": [{"key":"firstName","match":$scope.firstName,"value":$scope.studentSearchCriteria.studentfName},{"key":"lastName","match":$scope.firstName,"value":$scope.studentSearchCriteria.studentlName},],"searchUserInformationKey":["",],"start": 0}

1 个答案:

答案 0 :(得分:0)

您可以使用javascript push方法和角度复制方法angulat.copy(json)

studentSearchCriteria1.studentList1.push(angular.copy(secondJson));