Titanium 错误:在-[TiUITableViewProxy insertRowBefore:]中找不到行
我有一个tableview,其中包含从sqlite获取的数据。我可以通过将“编辑”设置为true来删除记录 我想在删除行之前检查一些条件。如果条件为true,则删除该行,但是如果条件为false,则会出现以下错误: 找不到索引的行。在-[TiUITableViewProxy insertRowBefore:](TiUITableViewProxy.m:500) 控制器Titanium 错误:在-[TiUITableViewProxy insertRowBefore:]中找不到行,titanium,tableview,appcelerator-mobile,Titanium,Tableview,Appcelerator Mobile,我有一个tableview,其中包含从sqlite获取的数据。我可以通过将“编辑”设置为true来删除记录 我想在删除行之前检查一些条件。如果条件为true,则删除该行,但是如果条件为false,则会出现以下错误: 找不到索引的行。在-[TiUITableViewProxy insertRowBefore:](TiUITableViewProxy.m:500) 控制器 有什么想法吗?我感觉表索引没有刷新。因此,当您在旧行索引下查找一行时,它认为那里什么都没有 试试这个: table.addEve
有什么想法吗?我感觉表索引没有刷新。因此,当您在旧行索引下查找一行时,它认为那里什么都没有 试试这个:
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);
}
}
虽然我不确定在设置数据后是否会松开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);
}
我还没有测试过这个,如果它不起作用,希望它至少能让你走上正轨:)
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);
}
table.addEventListener('delete', function(e) {
try{
db.execute("DELETE FROM tbltest WHERE rowid ='" + e.source.rowid + "'");
}
catch(e) {
alert('Deletion error' + e);
table.insertRowBefore(e.index, e.row);
}
}