AngularJS嵌套的ng-repeat不会修改模型。
创始人
2024-10-27 11:01:36
0

在AngularJS中,如果在嵌套的ng-repeat中发现无法修改模型的问题,可能是因为使用了原始的JavaScript对象作为ng-repeat的迭代器。解决方法是使用AngularJS中的内置方法$index来获取当前迭代的索引,并使用该索引来修改模型。

以下是一个示例代码:

angular.module('myApp', [])
  .controller('myController', function($scope) {
    $scope.items = [
      {
        subItems: [
          { name: 'Item 1' },
          { name: 'Item 2' },
          { name: 'Item 3' }
        ]
      },
      {
        subItems: [
          { name: 'Item 4' },
          { name: 'Item 5' },
          { name: 'Item 6' }
        ]
      }
    ];

    $scope.updateModel = function(parentIndex, index) {
      console.log(parentIndex, index);
      // 在这里可以修改模型
      // 例如:$scope.items[parentIndex].subItems[index].name = 'New Name';
    };
  });

在上面的示例中,我们使用了$parent.$index来获取父级ng-repeat的索引,$index来获取当前ng-repeat的索引。通过将这些索引传递给updateModel函数,我们可以在函数中修改模型。

请注意,在实际应用中,你可能需要根据具体的业务逻辑进行适当的修改。

相关内容

热门资讯

透视教程!德普之星透视辅助软件... 透视教程!德普之星透视辅助软件激活码(透视)开挂辅助app(好像真的有挂)-哔哩哔哩1、德普之星透视...
透视好友房!wepoker提高... 透视好友房!wepoker提高好牌率,wepoker好友局透视,手册教程(切实是有挂)-哔哩哔哩1、...
透视app!poker wor... 透视app!poker world辅助器(透视)开挂辅助器(好像是真的挂)-哔哩哔哩poker wo...
透视智能ai!wepoker买... 透视智能ai!wepoker买钻石有用吗,德州透视插件,方式教程(竟然存在有挂)-哔哩哔哩一、wep...
透视插件!红龙poker辅助器... 透视插件!红龙poker辅助器免费观看(透视)开挂辅助挂(其实真的是有挂)-哔哩哔哩1、透视插件!红...
透视脚本!pokerrrr2辅... 透视脚本!pokerrrr2辅助,wepoker私人局规律,法子教程(原来是有挂)-哔哩哔哩1.we...
透视实测!aapoker怎么设... 透视实测!aapoker怎么设置提高好牌几率(透视)开挂辅助攻略(真是真的是有挂)-哔哩哔哩所有人都...
透视透视挂!大菠萝免费辅助,w... 透视透视挂!大菠萝免费辅助,wepoker破解工具,方案教程(本来是有挂)-哔哩哔哩所有人都在同一条...
透视软件!hhpoker脚本(... 透视软件!hhpoker脚本(透视)开挂辅助app(其实是有挂)-哔哩哔哩所有人都在同一条线上,像星...
透视脚本!微扑克微乐辅助,we... 透视脚本!微扑克微乐辅助,wepoker透视有没有,窍门教程(确实有挂)-哔哩哔哩所有人都在同一条线...