脚本宝典收集整理的这篇文章主要介绍了Angular 1.X中 ng-repeat配合拖拽排序插件引起的问题,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
如图 拖拽完 并不会正常排序。发现引起问题的原因是track by $index
但我的数据渲染需要嵌套ng-rePEat
但我的数据渲染用到嵌套ng-repeat
,需要获取外部一层的$index
<tr ng-repeat="yAxis in tmpChartData.yAxis track by outIndex" ng-init="outIndex = $index">
<th>{{outIndex+2}}</th>
<th row-index="{{outIndex+1}}" tabindex="-1" editType="string">
<input type="text" ng-model="selectedElement.module.yAxis[outIndex]">
</th>
<th class="editTh" ng-repeat="xAxis in tmpChartData.xAxis" edit-chart-th row-index="{{outIndex+1}}" tabindex="-1">
<input type="number" ng-model="selectedElement.module.data[outIndex][$index]">
</th>
</tr>
解决方法 ng-repeat
还有一种 (key,val) in Arr
的写法 所以只要改写成
<tr ng-repeat="(outKey,outVal) in tmpChartData.yAxis" ng-init="outIndex = $index">
<th>{{outKey+2}}</th>
<th row-index="{{outKey+1}}" tabindex="-1" editType="string">
<input type="text" ng-model="selectedElement.module.yAxis[$index]">
</th>
<th class="editTh" ng-repeat="xAxis in tmpChartData.xAxis" edit-chart-th row-index="{{outIndex+1}}" tabindex="-1">
<input type="number" ng-model="selectedElement.module.data[outKey][$index]">
</th>
</tr>
以上是脚本宝典为你收集整理的Angular 1.X中 ng-repeat配合拖拽排序插件引起的问题全部内容,希望文章能够帮你解决Angular 1.X中 ng-repeat配合拖拽排序插件引起的问题所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。