哦,标题很长。
在我当前的项目中,我有一个网格来保存一组研讨会记录。对于每个研讨会,都有一组专门适用于给定研讨会的费率。
我的目标是为每一行显示一个组合框,其中显示特定于该工作坊的费率。
我有a prototype that works for the most part up on sencha fiddle ,但是选择值的创建方式有些不对劲:
Ext.define('Rates',{
extend: 'Ext.data.Store',
storeId: 'rates',
fields: [
'rateArray'
],
data:[
{
workshop: 'test workshop 1',
rateArray: {
rate1: {show: "yes", rate: "105", description: "Standard Registration"},
rate3: {show: "Yes", rate: "125", description: "Non-Member Rate"},
rate4: {show: "yes", rate: "44", description: "Price for SK tester"}
}
},
{
workshop: 'test workshop 2',
rateArray: {
rate1: {show: "yes", rate: "10", description: "Standard Registration"},
rate2: {show: "yes", rate: "25", description: "Non-Member Registration"}
}
}
]
});
Ext.define('MyGrid',{
extend: 'Ext.grid.Panel',
title: 'test combo box with unique values per row',
renderTo: Ext.getBody(),
columns:[
{
xtype: 'gridcolumn',
text: 'Name',
dataIndex: 'workshop',
flex: 1
},
{
xtype: 'widgetcolumn',
text: 'Price',
width: 200,
widget:{
xtype: 'combo',
store: [
// ['test','worked']
]
},
onWidgetAttach: function (column, widget, record){
var selections = [];
Ext.Object.each(record.get('rateArray'), function (rate, value, obj){
var desc = Ext.String.format("${0}: {1}", value.rate, value.description);
// according to the docs section on combobox stores that use 2 dimensional arrays
// I would think pushing it this way would make the display value of the combobox
// the description and the value stored the rate.
selections.push([rate, desc]);
});
console.log(selections);
widget.getStore().add(selections);
}
}
]
});
Ext.application({
name : 'Fiddle',
launch : function() {
var store = Ext.create('Rates');
Ext.create('MyGrid',{store: store});
}
});
在我用于组合框的网格小部件中,我使用 onWidgetAttach 方法来检查当前行的记录,将记录中的速率数据组装到二维数组中,然后将其设置到小部件的存储中。
当我查看 using a 2 dimensional array as the store 上的 sencha 文档部分时,它指出:
鉴于此,我希望组合框能够显示组装的描述(例如 “$150:标准注册”)并使用对象键作为实际存储值(例如“rate1”)。For a multi-dimensional array, the value in index 0 of each item will be assumed to be the combo valueField, while the value at index 1 is assumed to be the combo displayField.
我实际上看到的是显示值是速率,我不确定 sencha 如何生成组合框选择以查看选择是如何呈现的。
我关于二维数组如何转换为存储的假设是否错误?
最佳答案
嗯,你的问题受到 XY problem 的影响。 。因为您真正想做的是:
您想为您的组合创建一个像样的商店,使用定义良好的模型以及“rateArray”中已有的有意义的列名称,然后定义 displayField
和 valueField
相应地,在 onWidgetAttach
中,只需使用 setData
将“rateArray”对象填充到该存储中即可。
某事。沿着
xtype: 'widgetcolumn',
text: 'Price',
width: 200,
widget:{
xtype: 'combo',
store: Ext.create('Ext.data.Store',{
fields:['rate','description','show']
filters:[{property:'show',value:"yes"}]
}),
displayField:'description',
valueField:'rate',
onWidgetAttach: function (column, widget, record){
widget.getStore().setData(record.get("rateArray"));
}
},
关于javascript - 每行动态设置值时,Extjs 6 组合框值和显示值无法正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33372510/