如圖 拖拽完 並不會正常排序。發現引發問題的緣由是track by $index
但個人數據渲染須要嵌套ng-repeat
spa
但個人數據渲染用到嵌套ng-repeat
,須要獲取外部一層的$index
code
<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>