我正在研究离子项目,我在其中查看了一个按钮,用于从表格联系人中删除联系人。
这是观点:
<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 :(得分:0)
请您试试以下 -
var query = "DELETE FROM contacts WHERE id = ?";
$cordovaSQLite.execute(db, query, [item.id]);