如何删除使用钛合金框架
How may I delete using Titanium with Alloy Framework?
我试图使用Alloy框架只删除一条记录:
我在controller.js中创建了这段代码来显示我从ListView:中获得的变量
var args = arguments[0] || {};
$.titleLabel.text = args.titulo || 'Default Title';
$.authorLabel.text = args.author || 'Default Author';
我创建了这个删除功能:
function deleteBook(){
var books = Alloy.createCollection('books');
// The table name is the same as the collection_name value from the 'config.adapter' object. This may be different from the model name.
var table = books.config.adapter.collection_name;
// use a simple query
books.fetch({query:'Delete from ' + table + ' where titulo="' + args.titulo + '"'});
}
我用一个按钮调用函数,但我得到了这个错误:
[ERROR] : TiExceptionHandler: (main) [359476,359476] ----- Titanium Javascript Runtime Error -----
[ERROR] : TiExceptionHandler: (main) [0,359476] - In alloy/sync/sql.js:1,69
[ERROR] : TiExceptionHandler: (main) [0,359476] - Message: Uncaught TypeError: Cannot call method 'isValidRow' of null
[ERROR] : TiExceptionHandler: (main) [0,359476] - Source: (o)?r.execute(o):r.execute(o.statement,o.params);for(var c=0,u=[];d.isValidRow
[ERROR] : V8Exception: Exception occurred at alloy/sync/sql.js:1: Uncaught TypeError: Cannot call method 'isValidRow' of null
我只想能够从我的数据库中删除记录。
我找到了一种删除数据的方法:
在我的案例中,模型是books.js:
deleteRecord : function(opts) {
var collection = this;
var dbName = collection.config.adapter.db_name;
var table = collection.config.adapter.collection_name;
var columns = collection.config.columns;
var names = [], q = [];
for (var k in opts.query.columns) {
names.push(opts.query.columns[k]);
q.push("?");
}
var sql = "DELETE FROM " + table + " " + opts.query.sql;
db = Ti.Database.open(collection.config.adapter.db_name);
db.execute(sql, opts.query.params);
db.close();
collection.trigger('sync');
}
然后在控制器中:
function deleteBook () {
Alloy.Collections.books.deleteRecord({
query : {
sql : "WHERE title=?",
params : args.titulo
}
});
Alloy.Collections.books.fetch();
$.bookdetails.close();
}
就这样,工作得很好!
对于任何有这个问题的人,都可以在这个链接中查看完整的参考:
http://titaniumtuts.blogspot.com.br/2014/05/alloy-collection-crud.html#comment-表单
你好,我觉得有人会用另一种方式删除:
//Method for deleting
var myData= Alloy.Collections.data;
function delete(){
$.dialog.show();
//Dialog before delete
$.dialog.addEventListener('click', function(event) {
switch (event.index) {
case 0:
var note = myData.get(args.myId);
note.destroy();
//Show a toast message
var toast = Ti.UI.createNotification({
message:"deleted",
duration: Ti.UI.NOTIFICATION_DURATION_SHORT
});
toast.show();
$.detail.close();
break;
case 1:
null;
break;
}
});
}
相关文章:
- 避免在钛合金加速器中暂停应用程序
- 如何从“;“必需”;钛合金模块
- 如何删除使用钛合金框架
- MVC和钛合金,结构
- 钛合金未来的日子和时间倒计时
- 如何在钛(合金)图像视图中使用后置布局
- 钛合金布局
- 从钛合金中的选取器获取所选行
- 如何读取钛合金中的当地国家/地区电话代码xml
- 在钛合金调音器中设置视图和文本视图的 ID
- 钛合金JavaScript执行
- 关闭窗户并打开新窗口钛合金
- 我的iPhone 5s无法使用钛合金进行水平旋转
- 钛合金中的Android定向
- 钛合金开口标签组存在问题
- 打开和关闭钛合金窗户的正确方式
- 关闭模式并滚动到钛合金中的视图
- 如何在钛合金中隐藏/显示文本字段
- 如何将中的数据绑定到钛合金中的标签
- 钛合金MVC框架——“;型号“;查询