我感觉表索引没有刷新。因此,当您在旧行索引下查找一行时,它认为那里什么都没有。
试试这个:
table.addEventListener('delete', function(e) {
table.setData(table.data);
if(some condition){
db.execute("DELETE FROM tbltest WHERE rowid ='" + e.source.rowid + "'");
} else {
alert('Deletion is not possible');
table.insertRowBefore(e.index, e.row);
table.setData(table.data);
}
}
尽管我不确定您在执行 setData 后是否会丢失 e.row。另一个注意事项是,如果您要删除最后一行,这将不起作用。所以检查行的索引,比较行的长度,如果它更大,只需附加行。所以代码变成了
table.addEventListener('delete', function(e) {
table.setData(table.data);
if(some condition){
db.execute("DELETE FROM tbltest WHERE rowid ='" + e.source.rowid + "'");
} else {
// below will only work if you have 1 or no explicit sections in the table if you have more, you'll need to iterate through them
if (e.index >= table.data[0].rows.length) {
table.appendRow(e.row);
} else {
table.insertRowBefore(e.index, e.row);
}
table.setData(table.data);
}
我还没有测试过这个,如果它不起作用,希望它至少能让你走上正确的轨道:)