如何使用 ActionSheet 删除离子列表项?

How to delete an ion-list item using an ActionSheet?

我需要使用 ActionSheet(由暂停事件触发)而不是标准的 ng-click 从列表(从数组填充)中删除项目。

问题是我不知道如何通过索引号或项目 ID 来定位和删除它。

这里是 HTML:

<ion-list>
  <ion-item ng-repeat="mensaje in mensajes" class="item" ng-click="abrirMensaje()" 
  on-hold="mostrarMenu(mensaje)">
    <h2>{{ mensaje.alert }}</h2>
    <p>{{ mensaje.hid }}</p>
  </ion-item>
</ion-list>

这里是 ActionSheet 的控制器:

$scope.mostrarMenu = function(mensaje) {

    // Show the action sheet
    var hideSheet = $ionicActionSheet.show({
        buttons: [
            { text: '<b>Compartir</b>' },
        ],
        destructiveText: '<b>Eliminar</b>',
        cancelText: '<b>Cancelar</b>',
        cancel: function() {
    },
        buttonClicked: function(index) {
        return true;
        },
        destructiveButtonClicked: function(mensaje) {
            return true;
        }
    });
};

有什么想法吗?

我看到您在那里使用了 ng-repeat,因此您可以使用 $index

轻松传递索引
<ion-list>
    <ion-item ng-repeat="mensaje in mensajes" class="item" ng-click="abrirMensaje()" 
    on-hold="mostrarMenu(mensaje, $index)">
        <h2>{{ mensaje.alert }}</h2>
        <p>{{ mensaje.hid }}</p>
    </ion-item>
</ion-list>