如何从数组中设置 Sencha Touch 中的选择字段?
How to set a selectfield in Sencha Touch from array?
我在 Sencha Touch 应用程序中工作,我想推入一个组合框,之前从商店过滤的值。
var store = Ext.getStore('Surveys');
var templatesAvailable = [];
store.filterBy(function (record) {
console.log(record.get('templateName'));
record.get('templateName'); --> I get value
templatesAvailable.push(record.get('templateName')); --> into the array
});
下一步是将数组传输到指定的选择器,例如在我的例子中...
this.getTemplateSelector
{
xtype : 'selectfield',
itemId : 'selectSurveysTemplates',
cls : 'filterbar-selectfieldplus',
displayField: 'value', --> here is the secret ;-)
valueField : 'id',
autoCreate : true
},
这个实现的正确方法应该是什么?我已经用不同的选项进行了测试,但它对我不起作用..
提前谢谢你..
这个怎么样:
selectfield.setOptions(
store.getRange().map(function(record) {
return {
text:record.get("templateName"),
value:record.get("templateName")
};
})
);
这应该执行以下操作:
Selectfield.setOptions
sets the value of Selectfield.options
。根据文档,options
采用具有属性 text
和 value
的对象数组,所以我猜 setOptions
采用相同的属性。
Store.getRange
给你一组记录。
Array.map
接受一个函数并使用该函数转换输入数组中的每一项。
瞧,你应该完成了。
我在 Sencha Touch 应用程序中工作,我想推入一个组合框,之前从商店过滤的值。
var store = Ext.getStore('Surveys');
var templatesAvailable = [];
store.filterBy(function (record) {
console.log(record.get('templateName'));
record.get('templateName'); --> I get value
templatesAvailable.push(record.get('templateName')); --> into the array
});
下一步是将数组传输到指定的选择器,例如在我的例子中...
this.getTemplateSelector
{
xtype : 'selectfield',
itemId : 'selectSurveysTemplates',
cls : 'filterbar-selectfieldplus',
displayField: 'value', --> here is the secret ;-)
valueField : 'id',
autoCreate : true
},
这个实现的正确方法应该是什么?我已经用不同的选项进行了测试,但它对我不起作用..
提前谢谢你..
这个怎么样:
selectfield.setOptions(
store.getRange().map(function(record) {
return {
text:record.get("templateName"),
value:record.get("templateName")
};
})
);
这应该执行以下操作:
Selectfield.setOptions
sets the value ofSelectfield.options
。根据文档,options
采用具有属性text
和value
的对象数组,所以我猜setOptions
采用相同的属性。Store.getRange
给你一组记录。Array.map
接受一个函数并使用该函数转换输入数组中的每一项。
瞧,你应该完成了。