加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 09:34:09 所属栏目:安全 来源:网络整理
导读:如图 拖拽完 并不会正常排序。发现引起问题的原因是 track by $index 但我的数据渲染需要嵌套 ng-repeat 但我的数据渲染用到嵌套 ng-repeat ,需要获取外部一层的 $index tr ng-repeat="yAxis in tmpChartData.yAxis track by outIndex" ng-init="outIndex =

如图 拖拽完 并不会正常排序。发现引起问题的原因是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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读