【问题标题】:How to add selectable option to combobox without affecting the store on Sencha ExtJS 5?如何在不影响 Sencha ExtJS 5 上的商店的情况下向组合框添加可选选项?
【发布时间】:2015-05-07 13:05:18
【问题描述】:

所以我有一个视图,其中显示了一个组合框和一个共享“角色”商店的网格。如果您在组合框上选择一个选项,网格将被相应地过滤。

我正在寻找一种将“全部”选项添加到可选组合框的方法(因此占位符或值属性对我不起作用)。我想这样做是因为我无法在不影响网格的情况下将该选项添加到商店。

这是我的代码:

Ext.define("MODIFE.view.administration.Roles",{
    extend: "Ext.panel.Panel",
    xtype: "app-administration-roles",
    controller: "administration-roles",
    viewModel: {
        type: "administration-users"
    },

    title: "Roles",
    items:[
    {
        title: 'Búsqueda de Roles',
        frame: true,
        resizable: true,
        xtype: 'form',
        layout: 'column',

        defaults: {
            layout: 'form',
            xtype: 'container',
            defaultType: 'textfield',
            style: 'width: 50%'
        },

        items: [{
            items: [{
                fieldLabel: 'Rol',
                xtype: 'combobox',
                store: 'Roles',
                displayField: 'Description',
                valueField: 'RoleId',
            }]
        }, {
            items: [
                { fieldLabel: 'Estatus', xtype: 'combobox' },
            ]
        }],

        buttons: [
            { text: 'Nuevo' },
            { text: 'Buscar' }
        ]
    },
    {
        layout: 'fit',
        items: [{
            xtype: 'grid',
            id: 'rolesGrid',
            title: 'Listado de Roles',
            store: 'Roles',
            columns: [
                { text: 'Rol',  dataIndex: 'Description', flex: 2},
                { text: 'Estatus', dataIndex: 'Status', flex: 2},
            ]
        }]
    }]
});

提前致谢!

【问题讨论】:

    标签: extjs combobox store extjs5


    【解决方案1】:

    您可以克隆商店,然后任何更改都不会反映在原始商店中。 (但它很乱,如果启用此功能,同步可能会出现问题)

    //clone store
    var records = [],
        me = this;
    
    me.store.each(function(r){
        records.push(r.copy());
    });
    
    var store2 = new Ext.data.Store({
        recordType: me.store.recordType,
        model: me.store.model
    });
    
    store2.add(records);
    
    //add record
    store2.add({ID:"-1", NAME: "-Please select-"});
    

    【讨论】:

      猜你喜欢
      • 2014-11-06
      • 1970-01-01
      • 2011-10-04
      • 2011-01-02
      • 1970-01-01
      • 2021-06-10
      • 1970-01-01
      • 1970-01-01
      • 2012-12-21
      相关资源
      最近更新 更多