钛合金更新查询问题 [英] Issue with update query in titanium alloy

查看:32
本文介绍了钛合金更新查询问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是钛和合金框架的新手.我创建了模型来存储一些数据.我能够插入和检索数据.我不知道如何更新行.

I'm new to titanium and alloy framework. I have created the models to store some data. I am able to insert and retrieve the data. I don't know How to update the row.

按照我的建议,我做了以下,

As suggest I did as follows,

var userLang = Alloy.Collections.userLanguage;   
var models = Alloy.createModel("userLanguage");
    models.fetch({id: 1});
    models.save({
       languageID: langID,
       languageText: lang
    });

上面的代码没有显示任何错误,但是当我尝试从表中选择一行时,

The above code s not showing any error, But when I try to select a row from the table,

var userLang = Alloy.createModel('userLanguage');
 userLang.fetch({
        query: {
            statement: "SELECT * FROM userLanguage WHERE id = ?;",
            params: [ 1 ]
        }
    });
 alert("Updated value : "+userLang.get("languageText"));

模型

exports.definition = {
    config : {
        "columns": {
            "id": "integer",
            "languageID": "integer",
            "languageText": "text"
        },
        "adapter": {
            "type": "sql",
            "collection_name": "userLanguage"
        }
    }
};

所选行未按预期更新

推荐答案

...我需要钛查询...

...I need titanium query...

我猜你说的是 Backbone.如果是这样,那么您可以在下面看到如何更新模型的示例.

I guess that you are talking about Backbone. If so then below you can see an example how to update a model.

您可以在此处找到更多信息:http://docs.appcelerator.com/titanium/latest/#!/guide/Alloy_Sync_Adapters_and_Migrations

You can find more informations here: http://docs.appcelerator.com/titanium/latest/#!/guide/Alloy_Sync_Adapters_and_Migrations

var model = Alloy.createModel("userLanguage");

model.fetch({id: 1});

model.save({
   languageID: langID,
   languageText: lang
});

这篇关于钛合金更新查询问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆