ionic sqlite delete by id, item undefined

ionic sqlite delete by id, item undefined

本文关键字:item undefined id by sqlite delete ionic      更新时间:2023-09-26

我想从sqlite中删除一行,我的代码如下:

app.js

try {
    db = $cordovaSQLite.openDB({name:"inbox.db",location:'default'});
} catch (error) {
    alert(error);
}
$cordovaSQLite.execute(db, 'CREATE TABLE IF NOT EXISTS Messages (id INTEGER PRIMARY KEY AUTOINCREMENT, message TEXT)');

controllers.js

$scope.remove = function(item) {
    var query = "DELETE FROM Messages WHERE id = ?";
    $cordovaSQLite.execute(db, query, [item.id]).then(function(res) {
        console.warn('after query >  ' + item.id);
    }, function (err) {
        console.warn('error on deleting freaking off');
        console.error(err);
    });
};

,在html文件中我使用ng-click="remove(item)"

得到"undefined"对于item。id

显然我需要先定义项目,但不知道该怎么做!

你能贴出你的。html代码吗?

在填充列表时可能需要定义item:

<ion-item ng-repeat="item in items" item="item"></ion-item>