【发布时间】:2014-09-22 11:33:17
【问题描述】:
我是 Titanium API 的新手。我想知道如何从数据库中检索值并在 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();
}
我想从“UserLanguage”模型中选择“LanguageName”的值并显示在 XML 文件中的视图中。
请有任何解释的建议!
【问题讨论】:
标签: javascript titanium titanium-mobile titanium-alloy titanium-modules