【发布时间】:2023-03-25 18:00:01
【问题描述】:
我需要显示来自数据库的 Picker 值。那么如何在选择器中显示动态值。
XML 代码
<Alloy>
<Collection src="UserLanguage"/>
<Window class="container" onClose="cleanup">
<Picker class="picker">
<PickerColumn dataCollection="UserLanguage" dataTransform="transformFunction">
<PickerRow title="{LanguageName}"/>
</PickerColumn>
</Picker>
<!--<Label id="label"></Label>-->
</Window>
</Alloy>
型号:
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;
}
};
控制器
var moment = require('alloy/moment');
var userlang = Alloy.Collections.UserLanguage;
var task = Alloy.createModel('UserLanguage', {
id : '1',
LanguageName : 'English'
});
task.save();
userlang && userlang.fetch();
function transformFunction(model) {
var transform = model.toJSON();
transform.LanguageName = transform.LanguageName ;
return transform;
}
$.index.open();
function cleanup() {
$.destroy();
}
tss:
".container": {
backgroundColor:"black"
},
".picker": {
width: '90%',
top: '25dp'
}
Alloy.js
Alloy.Collections.UserLanguage = Alloy.createCollection('UserLanguage');
如何将选定的值传递给 Picker。数据未绑定到 XML 文件,我收到以下错误,
未捕获的类型错误:无法读取未定义的属性“_transform”
【问题讨论】:
标签: backbone.js titanium titanium-mobile titanium-alloy titanium-modules