【问题标题】:EXT-JS combo-box's store reset after expand when data is loaded dynamically动态加载数据时展开后EXT-JS组合框的存储重置
【发布时间】:2013-08-01 02:35:56
【问题描述】:

我想将项目动态添加到组合框项目。 这是它的定义:

{
      xtype: 'combobox',
      id: 'tierTypeCB',
      fieldLabel: 'Tiers\' type',
      labelWidth: 70,
      editable: false,
      valueField: 'type',
      displayField: 'type',
      store: Ext.create('Ext.data.Store',{
          fields: ['type'],
          data: []
      })
}

在代码的其他部分,我有这个应该添加项目的函数:

onGetTiersSuccess: function(response) { // this is a 'success' function of an AJAX request
    var decodedResponse = Ext.decode(response.responseText);
    var tierTypeCB =  Ext.getCmp('tierTypeCB');
    var tierTypesStore = tierTypeCB.getStore();
    for (var tierType in decodedResponse){
        tierTypesStore .add({type: tierType});
    }
}

问题是当下拉菜单打开时它是空的。我发现,我的代码将数据放入组合框的存储中,但是一旦扩展组合,存储就会被清空。 我已经使用 chrome 的控制台进行了更多测试。我注释掉了“onGetTiersSuccess”函数。相反,我只需在控制台中输入Ext.getCmp('tierTypeCB').getStore().add({type: 'abc'}) 如果我打开组合框,它是空的。但是,如果我首先打开组合框(在添加该项目之前),然后才添加该项目,一旦我再次打开组合框,我可以在那里看到我添加的项目。 似乎在打开组合框之前将项目添加到组合框,一旦打开组合框,就会“重置”组合框的商店。 我试图通过调用 Ext.getCmp('tierTypeCB').expand() 然后在添加项目之前调用 Ext.getCmp('tierTypeCB').collapse() 来绕过它,但这并没有帮助。 我也尝试过不在我定义它的地方设置组合框的商店,而是创建一个商店对象,然后将其绑定到组合框(使用bindStore() 命令),但这也没有帮助。

在这一点上我一无所知,所以如果你有任何可能对我有帮助的想法,我将不胜感激。

谢谢, 埃雷兹

【问题讨论】:

    标签: javascript extjs combobox


    【解决方案1】:

    您应该能够使用组合的lastQuery 配置来防止商店在首次展开时重新加载。

    {
        xtype: 'combobox',
        lastQuery: '',
        id: 'tierTypeCB',
        fieldLabel: 'Tiers\' type',
        labelWidth: 70,
        editable: false,
        valueField: 'type',
        displayField: 'type',
        store: Ext.create('Ext.data.Store',{
            fields: ['type'],
            data: []
        })
    }
    

    在此处查看文档:http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.field.ComboBox-property-lastQuery

    【讨论】:

    • +1 这对我有用,而 queryMode: 'local' 仍然加载,ty
    【解决方案2】:

    将queryMode 属性设置为local。发生的事情是在您尝试扩展组合框之前不会创建空商店。 queryMode 属性默认为 remote。将其设置为 local 应该可以解决问题,因为它会在创建组合框时加载商店。

    【讨论】:

    • 宾果游戏!!!!!!!!!!添加了所有额外的!因为评论有最小长度:-)
    猜你喜欢
    • 2013-09-14
    • 2011-11-18
    • 2013-08-16
    • 2015-05-30
    • 1970-01-01
    • 2011-04-16
    • 2019-06-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多