删除带有作用域数组的行将留下空白页



尝试在从数据库中删除一行后使用范围数组刷新视图,我没有运气:

$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');
        };
    });
};

此代码也成功删除行,但刷新功能不起作用。我尝试了选项1和选项2的答案。

 if (res) {
                $ionicPlatform.ready(function () {
                    $scope.chocolates = [];
                    var query = "DELETE FROM chocolates where name = ?";
                    $cordovaSQLite.execute(db, query, [x]);
                    $cordovaSQLite.execute(db, 'SELECT * FROM chocolates ORDER BY choc_id DESC LIMIT 1', []).then(function (res) {
                        if (res.rows.length > 0) {
                            for (var i = 0; i < res.rows.length; i++) {
                                $scope.chocolates.push(res.rows.item(i));
                            }
                        }
                    }, function (err) {
                        console.error(err);
                    });
                    $scope.$apply();
                });
            } else {
                console.log('You are not sure');
            };

最新更新