[英]Angular Dragula and ng-repeat $index
I have an ng-repeat of rows. 我有一排ng重复。 I set them up so you can reorder them with drag-and-drop using Angular Dragula. 我对其进行了设置,以便您可以使用Angular Dragula进行拖放来对其重新排序。 This works fine, but the ng-repeat $index
remains the initial value for each item after dragging. 这可以正常工作,但是ng-repeat $index
拖动后仍保持每个项目的初始值。 See screen captures below before and after a drag of the "Recipient" row. 拖动“收件人”行之前和之后,请参见下面的屏幕截图。
Is there a way to update the index? 有没有办法更新索引? I also want to re-order the menu with javascript, with that button in each row, but for that to work I need to get the current $index (and decrement/increment it) and that won't work if the index is incorrect like this. 我也想用javascript重新排列菜单,每行都有那个按钮,但是要正常工作,我需要获取当前的$ index(并递减/递增),如果索引不正确,那将不起作用像这样。
尝试通过$ index添加ng-repeat曲目。
For what it's worth, this is the answer: 对于它的价值,这是答案:
<div class="table-cards-body" dragula="'first-bag'" dragula-model="home.quickReceiveFields">
<div class="table-cards-row drag-item" ng-repeat="field in home.quickReceiveFields track by $index">
<div class="one">{{field.name}}</div>
<div class="two">{{field.type}}</div>
<div class="three">{{field.default}} {{$index}}</div>
<div class="four"><input type="checkbox" ng-model="field.display"></div>
<div class="five"><input type="checkbox" ng-model="field.retain"></div>
<button class="btn btn-default btn-xs" ng-click="home.moveItemUp($index)">^</button>
</div>
</div>
Despite what the docs say on the angular-dragula site , you need to put the dragula-model
attribute on the container into which you put the repeating items. 尽管文档在angular-dragula站点上说了什么,您仍需要将dragula-model
属性放在要放置重复项的容器上 。 Not the ng-repeat
itself. 不是ng-repeat
本身。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.