Angular 1.X中 ng-repeat配合拖拽排序插件引发的问题

如图 拖拽完 并不会正常排序。发现引发问题的缘由是track by $index
但个人数据渲染须要嵌套ng-repeatspa

图片描述

但个人数据渲染用到嵌套ng-repeat,须要获取外部一层的$indexcode

<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 的写法 因此只要改写成blog

<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>
相关文章
相关标签/搜索