在从数据库中删除一行后,尝试用范围数组刷新视图,但没有成功:
$scope.remove = function() {
var x = document.getElementById("name").textContent;
$cordovaSQLite.execute(db, 'DELETE from table WHERE name=?', [x])
.then(function(res) {
var index = $scope.listItems.indexOf(x);
$scope.listItems.splice(index, 1);
}, function(error) {
console.log(error.message);
})
};
删除成功,但留下一个空白页面。要在我的Ionic应用程序中刷新,我必须转到另一个页面,然后返回:
$scope.showConfirm = function () {
var x = document.getElementById("name").textContent;
var confirmPopup = $ionicPopup.confirm({
title: 'Deleting Journal Entry',
template: 'Are you sure you want to delete this item ?'
});
confirmPopup.then(function (res) {
if (res) {
var query = "DELETE FROM chocolates where name = ?";
$cordovaSQLite.execute(db, query, [x]);
$state.go($state.current, $stateParams, {reload: true, inherit: false});
console.log(x);
} else {
console.log('You are not sure');
};
});
};
这段代码也成功地删除了行,但是刷新功能不起作用。我尝试了alternative 1和alternative 2的答案。
1条答案
按热度按时间9jyewag01#
这就是解决办法。