【问题标题】:Deleting SQLite row with Scope array Leave Blank Page使用范围数组删除 SQLite 行保留空白页
【发布时间】:2016-10-29 18:04:58
【问题描述】:

在我的 SQLite cordova 插件上删除一行数小时后,我试图刷新范围内的视图,但没有运气。

代码:$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 Platform 应用程序,我必须转到其他页面而不是返回。

其他代码:$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 1alternative 2的许多答案

如果我能找到任何帮助,我将不胜感激,谢谢

【问题讨论】:

  • 没有人?哦,亲爱的..碰碰!

标签: arrays angularjs sqlite cordova ionic-framework


【解决方案1】:

经过几天的调试和阅读,终于找到了解决方案!

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

到目前为止,这是更清洁的解决方案,如果没有人提出更好的主意,我会接受我自己的答案。希望也能帮助那里的人。

【讨论】:

    猜你喜欢
    • 2017-02-15
    • 1970-01-01
    • 2014-09-24
    • 2018-08-09
    • 2019-07-05
    • 2021-11-29
    • 2011-12-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多