如何在ion-list中使用数组拼接方法

时间:2016-04-18 06:55:34

标签: angularjs ionic-framework

当我们将列表向左滑动时,我有一个数据列表,用于删除具有删除功能的离子列表。

我能够使删除功能正常工作,但是当响应为真时,我被困在如何拼接列表。

我正在使用$scope.data.splice($index, 1);

这是我的代码

HTML

<ion-item ng-repeat="x in data track by $index" href="#/item/{{x.mif_no}}" class="item-remove-animate">
    <ion-option-button class="button-assertive icon ion-trash-a" on-touch="Delete(x.mif_no,x.item_no)"></ion-option-button>
</ion-item>

这是js代码

JS

$scope.Delete = function(docno,itemno){
$http({
  method: "post",
  url: apiServer + "/fg-in-del.php",
  data: {
    mifno: docno,
    itemno: itemno,
    Dbserver: window.localStorage.getItem("server"),
    Dbuser: window.localStorage.getItem("username"),
    Dbpass: window.localStorage.getItem("password"),
    Dbname: window.localStorage.getItem("dbname"),
  },
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
  }
}).then(function(response) {
  $scope.data=response.data;
  if (response.data == 1){
    var alertPopup = $ionicPopup.alert({
      title: 'Delete',
      template: 'Data has been deleted.'
    });
    $scope.data.splice($index, 1);
  }else {
    var alertPopup = $ionicPopup.alert({
      title: 'Delete',
      template: 'Failed to delete data.'
    });
    console.log(response.data);
  }
}, function(response) {
  $scope.data=response.data;
  var alertPopup = $ionicPopup.alert({
    title: 'Delete',
    template: 'Failed to delete data.'
  });
});
}

2 个答案:

答案 0 :(得分:0)

此代码永远不会起作用,因为:

如果你设置

$scope.data=response.data;

然后检查

if (response.data == 1){

$scope.data必须在此if条件下1

拼接1是不是可能?因此

$scope.data.splice($index, 1);

没有工作。

答案 1 :(得分:0)

JS

 $scope.Delete = function(docno,itemno,index){
      $http({
        method: "post",
        url: apiServer + "/fg-in-del.php",
        data: {
          mifno: docno,
          itemno: itemno,
          Dbserver: window.localStorage.getItem("server"),
          Dbuser: window.localStorage.getItem("username"),
          Dbpass: window.localStorage.getItem("password"),
          Dbname: window.localStorage.getItem("dbname"),
        },
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded',
        }
      }).then(function(response) {
        if (response.data == 1){
          var alertPopup = $ionicPopup.alert({
            title: 'Delete',
            template: 'Data has been deleted.'
          });
          $scope.data.splice(index, 1);
        }else {
          var alertPopup = $ionicPopup.alert({
            title: 'Delete',
            template: 'Failed to delete data.'
          });
          console.log(response.data);
        }
      }, function(response) {
        $scope.data=response.data;
        var alertPopup = $ionicPopup.alert({
          title: 'Delete',
          template: 'Failed to delete data.'
        });
      });
    }

HTML

<ion-item ng-repeat="x in data track by $index" ng-hide="x.deleted" href="#/item/{{x.mif_no}}" class="item-remove-animate">
    <ion-option-button class="button-assertive icon ion-trash-a" on-touch="Delete(x.mif_no,x.item_no, $index); x.deleted = true;"></ion-option-button>
</ion-item>