简体   繁体   English

数组中的angularjs对象上没有$$ hashKey

[英]No $$hashKey on angularjs object in array

$scope.create (in CreateCtrl) and $scope.list (inListCtrl) linked to DOM For some reason, $ $ hashKey not added to all objects. 链接到DOM的$ scope.create(在CreateCtrl中)和$ scope.list(在ListListCtrl中)由于某种原因,未将$ $ hashKey添加到所有对象中。 The last object is left without him. 最后一个对象没有他。 That is, if I added 3 items, the third less $ $ hashkey if add another, then a third appears hashkey $ $, and the fourth is not. 也就是说,如果我添加了3个项目,则第三个减去$ $哈希键,如果添加了另一个,则第三个出现了哈希键$ $,而第四个则没有。

Because of this error appears: Error: [ngRepeat:dupes] 因为出现此错误:错误:[ngRepeat:dupes]

track by $index does not offer. $ index跟踪不提供。 Then sorting stops working. 然后分类停止工作。

app.controller('CreateCtrl', function ($scope) {
   $scope.create = {a:1, b:2, c:3};
   $scope.send = function () {
      $scope.$emit('send', angular.copy($scope.create));
   }
});

app.controller('ListCtrl', function ($scope, $rootScope) {
   $scope.list = [];
   $rootScope.$on('send', function (e, data) {
      $scope.list.push(data);
   });
});

You're passing a javascript object {} with three elements and then pushing that whole object into the first index of $scope.list 您要传递具有三个元素的javascript对象{} ,然后将整个对象推入$scope.list的第一个索引中

$rootScope.$on('send',function(e,data){
    angular.forEach(data,function(value,key){
        $scope.list.push(value); // or $scope.list[key] = value;
    });
});

Your values are at data.a , data.b and data.c 您的值位于data.adata.bdata.c

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM