【问题标题】:ng-repeat with filter on several view bug my $indexng-repeat 过滤几个视图错误我的 $index
【发布时间】:2015-12-17 09:24:55
【问题描述】:

我有 2 个视图

view1.html

<li ng-repeat="post in posts | filter: { section: 'principal'} ">

view2.html

<li ng-repeat="post in posts | filter: { section: 'bug' } ">

您可以在 view1 上看到我有一个过滤器,它只显示具有 view2 的“主要”和“错误”部分的帖子。

现在我添加一个值为“principal”的新帖子,该帖子出现在 view1 ($index=1) 中。
在视图 2 中添加一个值为“bug”($index=2)的帖子后。 最后,我在 view1 中再次添加了一个新帖子($index =3)

对于简历,我在 view1 上有 2 个帖子,在 view2 有 1 个帖子

但是如果我点击 view2 上的帖子,我遇到了 $index 问题,他看到他在列表中的第一位,所以他使用 index1 并更改了我在 view1 中创建的第一个帖子。

我该如何解决这个问题?

我希望我已经足够清楚地说明了这一点。 谢谢你的回答

编辑:
这是他调用函数passerDroite的按钮

<a class="waves-effect white-text" ng-show="!editing[$index]" ng-click="passerDroite($index)"> >> </a>

这就是她刚刚修改“etat”的功能:

 $scope.passerDroite = function(index){
        var post = $scope.posts[index];
        post.etat = "enCours";
        Posts.update({id: post._id}, post);
        $scope.editing[index] = false;
    }

我只是编辑有点问题:

    $scope.editing = [];
    $scope.posts= Posts.query();

    $scope.edit = function(index){
    $scope.editing[index] = angular.copy($scope.posts[index]);
    }

我试试这个:

 $scope.edit = function(post){
    post = angular.copy(post);
 } 

是否可以通过帖子找到索引?喜欢 post.index 吗?

【问题讨论】:

  • 首先你应该在你的 ng-repeats 中使用“track by $index”。其次,请发布点击代码
  • 我编辑了我的问题,我向您展示了我与 $index 一起使用的一个函数
  • 使用ng-click="passerDroite(post)$scope.passerDroite = function(post){
  • 谢谢你这工作

标签: angularjs mongodb filter angularjs-ng-repeat


【解决方案1】:

这是一个已知问题 - 尝试传入实际对象而不是索引,因为 Johannes Jander 已经指出 ng-click="passerDroite(post)"function(post){

【讨论】:

  • 我的帖子编辑功能还是有一点小错误
  • 据我在文档docs.angularjs.org/api/ng/function/angular.copy 中看到的语法是 angular.copy(source, [destination]);所以你的代码应该是: angular.copy(post, destinationpost);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-09-19
  • 2017-01-28
  • 1970-01-01
  • 2015-03-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多