Javascript 如何从钛合金数据库中检索值?

Javascript 如何从钛合金数据库中检索值?,javascript,titanium,titanium-mobile,titanium-alloy,titanium-modules,Javascript,Titanium,Titanium Mobile,Titanium Alloy,Titanium Modules,我对钛API是新手。我想知道如何从DB中检索值并在UI中显示。我创建了一个模型并插入了一行。我的代码如下: 型号: var moment = require('alloy/moment'); exports.definition = { config : { "columns": { "id":"text", "LanguageName":"text" }, "ada

我对钛API是新手。我想知道如何从DB中检索值并在UI中显示。我创建了一个模型并插入了一行。我的代码如下:

型号:

var moment = require('alloy/moment');

exports.definition = {
    config : {
            "columns": {
            "id":"text",
            "LanguageName":"text"
            },
            "adapter": {
                "type": "sql",
                "collection_name": "UserLanguage"
            }
    },

    extendModel: function(Model) {      
        _.extend(Model.prototype, {

        });

        return Model;
    },

    extendCollection: function(Collection) {        
        _.extend(Collection.prototype, {

        });

        return Collection;
    }
};
<Alloy>
    <Window id="changeLangWindow" title="Plan India">
        <Picker id="langPicker">
            <PickerRow title="Select a Language"/>
            <PickerRow title="English"/>
            <PickerRow title="French"/>
            <PickerRow title="Spanish"/>
        </Picker>
        <Button class="button" onClick="saveLang">Proceed</Button>
        <Label class="question">Selected Language is: -------</Label>
    </Window>
</Alloy>
function saveLang() {

    var UserLang = Alloy.Collections.UserLanguage;

    // Create a new model for the todo collection
    var task = Alloy.createModel('UserLanguage', {
        id : '1',
        LanguageName : 'English'
    });

    // add new model to the global collection
      UserLang.add(task);

    // save the model to persistent storage
    task.save();

    // reload the tasks
     UserLang.fetch();

}
查看:

var moment = require('alloy/moment');

exports.definition = {
    config : {
            "columns": {
            "id":"text",
            "LanguageName":"text"
            },
            "adapter": {
                "type": "sql",
                "collection_name": "UserLanguage"
            }
    },

    extendModel: function(Model) {      
        _.extend(Model.prototype, {

        });

        return Model;
    },

    extendCollection: function(Collection) {        
        _.extend(Collection.prototype, {

        });

        return Collection;
    }
};
<Alloy>
    <Window id="changeLangWindow" title="Plan India">
        <Picker id="langPicker">
            <PickerRow title="Select a Language"/>
            <PickerRow title="English"/>
            <PickerRow title="French"/>
            <PickerRow title="Spanish"/>
        </Picker>
        <Button class="button" onClick="saveLang">Proceed</Button>
        <Label class="question">Selected Language is: -------</Label>
    </Window>
</Alloy>
function saveLang() {

    var UserLang = Alloy.Collections.UserLanguage;

    // Create a new model for the todo collection
    var task = Alloy.createModel('UserLanguage', {
        id : '1',
        LanguageName : 'English'
    });

    // add new model to the global collection
      UserLang.add(task);

    // save the model to persistent storage
    task.save();

    // reload the tasks
     UserLang.fetch();

}
我想从“UserLanguage”模型中选择“LanguageName”的值,并显示在XML文件中的视图中


有任何建议请解释

//试试这段代码,可能会对您有所帮助

if (Alloy.Collections.UserLanguage.length) {
     Alloy.Collections.UserLanguage.map(function(obj) {

        Ti.API.Log(" LanguageName "+ obj.get('LanguageName'));
        Ti.API.Log(" LanguageName "+ obj.id);

     });

}

谢谢,

是的,它正在工作。但是我如何编写WHERE条件,比如selectlanguagename,其中id=7;另外,我们如何在UI上显示所选的值。这就是如何将所选值从js文件传递到xml的方法?您可以通过ID“var model=Alloy.Collections.UserLanguage.get(“您的ID”);”获取这样的值。如果我们在select查询中获取多个值,我们如何处理它?如果这个答案对您有效或有帮助。然后接受这个答案:)谢谢