track by与普通in循环区别

<divng-repeat="links in slides"><div ng-repeat="link in links track by $index">{{link.name}}</div></div>

Error: [ngRepeat:dupes]


you can 'track by $index' if your data source has duplicate identifiers

e.g.: $scope.dataSource: [{id:1,name:'one'}, {id:1,name:'one too'}, {id:2,name:'two'}]

you can't iterate this collection while using 'id' as identifier (duplicate id:1).

WON'T WORK:

<element ng-repeat="item.id as item.name for item in dataSource">
  // something with item ...
</element>

but you can, if using 'track by $index':

<element ng-repeat="item in dataSource track by $index">
  // something with item ...
</element>

这个出错提示具体到的情况,意思是指数组中有2个以上的相同数字。ngRepeat不允许collection中存在两个相同Id的对象

For example: item in items is equivalent to item in items track by $id(item). This implies that the DOM elements will be associated by item identity in the array.

对于数字对象来说,它的id就是它自身的值,因此,数组中是不允许存在两个相同的数字的。为了规避这个错误,需要定义自己的track by表达式。

例如:item in items track by item.id或者item in items track by fnCustomId(item)。嫌麻烦的话,直接拿循环的索引变量$index来用item in items track by $index

</pre><html><pre name="code" class="html"><div ng-app>
    <div ng-controller="test">
        <div ng-repeat="links in slides">
            <hr/>
            <div ng-repeat="link in links track by $index">
                {{link}}
            </div>
        </div>
    </div>
</div>

<script>
function test($scope) {
    $scope.slides = [
        [ 1, 1, 1 ],
        [ 4, 5, 6 ],
    ];
}
</script>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用中提到了"Research on precision windowed track mode for in-orbit calibration on star tracker"。这是一种用于在轨星敏感器进行精确窗口跟踪模式的校准的研究。而引用中提到了" A track before detect algorithm for infrared (IR) point target is developed based on particle filter"。这是一种基于粒子滤波器开发的红外(IR)点目标的"track before detect"算法。根据这两个引用,我们可以得出结论:在轨中的"for in track"可能指的是在轨道中进行目标跟踪的过程。<span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* [Research on precision windowed track mode for in-orbit calibration on star tracker](https://download.csdn.net/download/weixin_38546308/15152826)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [Track before detect for point targets with particle filter in infrared image sequences](https://download.csdn.net/download/weixin_38635684/15204259)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值