在嵌套的ng-repeat中通过$index跟踪的最佳方法是什么?
What would be the best way to track by $index in nested ng-repeat?
我有以下HTML:
<div class="row" ng-repeat="row in grid track by $index">
<div cell class="cell" ng-repeat="cell in row track by $index" ng-click="game.addItem($index, $index)">
{{cell.value}}
</div>
</div>
我需要在第一个ng-repeat和第二个ng-repeat中按索引跟踪,以便将它们传递给addItem()。通过这两项考试的最好方法是什么?
我相信你能做到:
<div class="row"
ng-repeat="row in grid track by $index"
ng-init="$rowIndex = $index">
<div cell class="cell"
ng-repeat="cell in row track by $index"
ng-click="game.addItem($rowIndex, $index)">
{{cell.value}}
</div>
</div>
(Init可能需要放在外部div上,因为我坐在这里记不清了)
尽管问题来了,为什么不能直接使用单元格和行呢?为什么需要索引呢?
<div class="row" ng-repeat="row in grid track by $index">
<div cell class="cell" ng-repeat="cell in row track by $index"
ng-click="game.addItem(row, cell)">
{{cell.value}}
</div>
</div>
相关文章:
- 动态分配GA增强型电子商务跟踪器
- 跟踪在页面加载时应用内联样式的JavaScript
- 在localhost Dev Box上测试JSONP请求的最佳方式
- 有条件更新d3.js力图中节点的最佳方法
- 跟踪用户点击Adsense广告的IP地址
- 为react组件传递道具的最佳方式
- 与运行长作业(javascript,node.js)的第三方API同步的最佳实践
- 让Webpack管理Quirky AMD定义的最佳方式
- 跟踪jqplot垂直折线图的鼠标位置
- 在承诺链中处理早期回报的最佳方式
- 将jQuery.ech()方法转换为本地JavaScript抽象的最佳方法是什么
- 点击facebook像素跟踪注册(JS/JQUERY代码)
- 跟踪 Jquery 和 CSS 标识符的最佳方法是什么?
- 在 Web 应用中处理事件跟踪的最佳(高性能)方法
- 跟踪javascript中文本框控件上触发的退格事件位置的最佳方法
- 在Javascript中跟踪方法调用的最佳方式
- 使用KnockoutJs跟踪初始映射的最佳方式
- 在原型设计时跟踪javascript对象引用的最佳方法是什么?
- 在嵌套的ng-repeat中通过$index跟踪的最佳方法是什么?
- 通过javascript跟踪表单更改的最佳方式是什么