2016-11-22 140 views
0

我正在研究離子項目,我認爲該項目有一個按鈕可以從表格聯繫人中刪除聯繫人。如何從SQLite中刪除項目angularJS

這是視圖:

<ion-list> 
    <ion-item ng-repeat="item in list" class="item-remove-animate" item="item" > 
     {{ item.firstname }} 
     {{ item.lastname}} 
     <ion-option-button class="button-royal" ng-click="edit($index)"> 
      Edit 
     </ion-option-button> 
     <ion-option-button class="button-assertive" ng-click="del(item)"> 
      delete 
     </ion-option-button>   
    </ion-item> 
</ion-list> 

這是按鈕刪除的聯繫人:

<ion-option-button class="button-assertive" ng-click="del(item)"> 

刪除按鈕將顯示一個確認彈出消息時,如果用戶確認刪除,然後當前聯繫人將從數據庫中的contacts表中刪除。

這是控制器:

$scope.del = function(item) { 

    var confirmPopup = $ionicPopup.confirm({ 
    title: 'Delete contact', 
    template: 'Are you sure you want to delete?' }); 

    confirmPopup.then(function(res) { 
    if(res) { 

    var query = "DELETE FROM contacts WHERE id = (?)"; 
     $cordovaSQLite.execute(db, query, [item.id]); 
     $state.go($state.current, $stateParams, {reload: true, inherit: false}); 

}; 

接觸不會被刪除,當我手動插入ID如下:

$cordovaSQLite.execute(db, query, [1]); 

它的工作原理,否則它沒有,這是什麼問題?

回答

0

能不能請你用下面 -

var query = "DELETE FROM contacts WHERE id = ?"; 
$cordovaSQLite.execute(db, query, [item.id]);