Onsen UI Carousel Swipe list item

﹥>﹥吖頭↗ 提交于 2019-12-07 18:23:13

问题


i am using the carousel feature of the onsen ui framework in order to delete items in a list by swiping from left to right, like in ios/android. The swipe displays a "delete"-button which should delete this item from the list and reorder it The problem is, the view always deletes the last row instead the one i pressed the button on, however, the row is removed correctly in the dataarray.

Does anyone have an answer for that??

*hope that there is s.o. out there with a solution


回答1:


You should supply some code so we can see what you've tried. Are you using the ngRepeat directive and a <ons-list>? In that case you should just remove the item from the data array.

In a controller you create a list of items (can be anything):

angular.module('myApp').controller('MyController', function($scope) {
  $scope.items = ['A', 'list', 'of', 'items'];
});

In your HTML you use ngRepeat to loop through them. To remove an item use ngClick and splice the list.

<ons-list>
  <ons-list-item ng-repeat="item in items">
    {{ item }}
    <ons-button ng-click="items.splice($index, 1)">Remove item</ons-button>
  </ons-list-item>
</ons-list>

I've used carousel in the following example, but it shouldn't really matter what you put in your list. http://codepen.io/argelius/pen/qEmjEB



来源:https://stackoverflow.com/questions/28031146/onsen-ui-carousel-swipe-list-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!