简体   繁体   中英

Angular Dragula and ng-repeat $index

I have an ng-repeat of rows. I set them up so you can reorder them with drag-and-drop using Angular Dragula. This works fine, but the ng-repeat $index remains the initial value for each item after dragging. 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.

Before Drag

在此处输入图片说明

After Drag

在此处输入图片说明

尝试通过$ 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. Not the ng-repeat itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM