如何从钛合金中的数据库中检索值? [英] How to retrive values from Database in Titanium Alloy?
本文介绍了如何从钛合金中的数据库中检索值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Titanium API的新手。我想知道如何从数据库中检索值并在UI中显示。我创建了一个模型并插入了一行。我的代码如下,
I'm new to Titanium API. I want to know how to retrieve values from DB and display in UI. I created a model and inserted a row. My code is as below,
型号:
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模型并在视图中显示在XML文件中。
I want to select the value of "LanguageName" from "UserLanguage" model and display in the View that is in XML file.
任何有解释的建议都可以!
Any suggestions with explanation please!
推荐答案
//尝试此代码可能对您有所帮助。
// Try this code May be this is helpful for you.
if (Alloy.Collections.UserLanguage.length) {
Alloy.Collections.UserLanguage.map(function(obj) {
Ti.API.Log(" LanguageName "+ obj.get('LanguageName'));
Ti.API.Log(" LanguageName "+ obj.id);
});
}
谢谢,
这篇关于如何从钛合金中的数据库中检索值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文