Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 每行动态设置值时,Extjs 6组合框值和显示值未正确显示_Javascript_Extjs_Combobox - Fatal编程技术网

Javascript 每行动态设置值时,Extjs 6组合框值和显示值未正确显示

Javascript 每行动态设置值时,Extjs 6组合框值和显示值未正确显示,javascript,extjs,combobox,Javascript,Extjs,Combobox,哦,那是一个很长的标题 在我当前的项目中,我有一个网格,其中保存了一组车间记录。对于每个研讨会,都有一套专门适用于给定研讨会的费率 我的目标是为每一行显示一个组合框,显示特定于该工作车间的费率 我知道了,但是关于选择值是如何创建的,有点不对劲: Ext.define('Rates',{ extend: 'Ext.data.Store', storeId: 'rates', fields: [ 'rateArray' ], data:[

哦,那是一个很长的标题

在我当前的项目中,我有一个网格,其中保存了一组车间记录。对于每个研讨会,都有一套专门适用于给定研讨会的费率

我的目标是为每一行显示一个组合框,显示特定于该工作车间的费率

我知道了,但是关于选择值是如何创建的,有点不对劲:

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方法检查当前行的记录,将记录中的速率数据组装到二维数组中,然后将其设置到小部件的存储中

当我查看上的sencha docs部分时,它指出:

对于多维数组,每个项的索引0中的值将假定为组合值字段,而索引1中的值将假定为组合显示字段

考虑到这一点,我希望组合框显示组装的描述(例如。 “$150:标准注册”)并使用对象键作为实际存储值(例如“rate1”)

我实际上看到的是显示值是速率,我不确定sencha如何生成组合框选择,以查看选择是如何渲染出来的


我关于二维数组如何转换为存储的假设是错误的吗?

好吧,你的问题受到了限制。因为你真正想做的是:

你想为你的组合创建一个像样的存储,使用一个定义良好的模型,使用“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"));
    }
},

好吧,你的问题受到了质疑。因为你真正想做的是:

你想为你的组合创建一个像样的存储,使用一个定义良好的模型,使用“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"));
    }
},

很好,即使添加了snark:/。非常感谢。昨天是一个漫长的工作,这是我第一个使用该框架的重大项目。创建门店绝对是更容易/更符合逻辑的方式。rateArray名称是从将其转换为对象的重构中遗留下来的。名字也被更新了。谢谢。对不起,我的打扰;我不是故意的。现在应该更好了。很好,即使增加了snark:/。非常感谢。昨天是一个漫长的工作,这是我第一个使用该框架的重大项目。创建门店绝对是更容易/更符合逻辑的方式。rateArray名称是从将其转换为对象的重构中遗留下来的。名字也被更新了。谢谢。对不起,我的打扰;我不是故意的。现在应该好多了。