javascript - AngularJS 将两个列表合二为一

标签 javascript angularjs merge push

我正在使用 angularJS,我遇到了一个问题: 我有 2 个 $scope:

$scope.list1{
Object 1,
Object 2,
Object 3}

$scope.list2{
Object 4,
Object 5,
}

我想要这个结果:

$scope.res{
Object 1,
Object 2,
Object 3,
Object 4,
Object 5}

agularJS不知道用什么函数,我用过

angular.merge($scope.res, $scope.list1, $scope.list2)

但我得到的结果是空的 我不知道 merge 是不是好的功能所以我需要你的帮助

最佳答案

Angular 方式 将使用 angular.extend :

Extends the destination object dst by copying own enumerable properties from the src object(s) to dst. You can specify multiple src objects. If you want to preserve original objects, you can do so by passing an empty object as the target: var object = angular.extend({}, object1, object2).

angular.extend($scope.list1, $scope.list2);

关于javascript - AngularJS 将两个列表合二为一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43763668/

相关文章:

javascript - NG-repeat 不是从示波器中读取数据吗?

Github pull 请求 : There isn't anything to compare

javascript - JavaScript 中的继承导致 Uncaught TypeError

php - 在 PHP 中提交表单时声音无法完成

javascript - Popover Bootstrap - 如何让它更干净

javascript - Extjs 同步商店给我一个 url is undefined error under specific conditions

jquery - 将AngularJS扩展到现有的jQuery大量应用程序中

javascript - AngularJS 中的 Kendo Sortable 事件,如何捕获?

PHP脚本压缩/"Compilation"工具

git - 为什么我需要在解决 merge 冲突后执行 'git add <files>'?