【问题标题】:Store filtering for combobox and bindStore组合框和 bindStore 的存储过滤
【发布时间】:2015-01-06 19:38:52
【问题描述】:

在单独的函数中使用 bindStore 将商店绑定到组合框。

一切正常 - 除了我需要根据给定参数过滤该函数中的数据。

  loadMarkers: function(store, value){

    store.filter('markerid',17);

    this.fields.marker.bindStore(store);
    this.fields.marker.setValue(value);
  }

这个具体的例子有两种不同的方式我试过了——绑定之前和之后。最后的 Console.log 显示了“存储”甚至组合框的过滤存储。但是组合框本身仍然显示所有内容。

组合框配置:

  marker: new Ext.form.ComboBox({
    fieldLabel: _('Marker'),
    displayField: 'name',
    valueField: 'id',
    mode:'local',
    lastQuery: '',
    store: new Ext.data.JsonStore({
      fields: ['name', 'id', 'markerid'],
      data: [
        {name:_('Default'), id: 0, markerid: 0}
      ]
    })
   })

this.markerStore = new Ext.data.JsonStore({
  autoLoad: true,
  url: 'Api/getMarkers',
  root: 'response',
  sortInfo: {field: 'name', direction: 'ASC'},
  fields: Ext.data.Record.create([
    {name: 'id', type: 'integer'},
    {name: 'name', type: 'string'},
    {name: 'markerid', type: 'integer'}
  ])
});

【问题讨论】:

  • 你也可以显示你的商店配置
  • 已更新商店配置
  • 你使用的是什么版本的 Ext?我会在几分钟内发布一些代码
  • ext 3.4(标签中的ext3)

标签: javascript extjs ext3


【解决方案1】:

由于上面代码的格式,我假设您正在使用 ExtJs 3.4 来回答这个问题。

我尝试直接运行您的代码,但出现了一些错误。例如_('Default') _() is undefined,从我在文档中可以看到,ComboBox 没有名为bindStore ComboBox Documation 的函数。

我已将代码重写为以下代码,它对我来说很好。您需要确保在商店加载数据之后应用过滤器,在我的示例中,我等待加载事件被触发。

Ext.onReady(function() {

    Ext.BLANK_IMAGE_URL = '/js/ext-3.4.0/resources/images/default/s.gif';

    var markerStore = new Ext.data.JsonStore({
        autoLoad: true,
        url: 'data/data1.json',
        root: 'rows',
        sortInfo: {field: 'name', direction: 'ASC'},
        fields: [
            {name: 'id', type: 'integer'},
            {name: 'name', type: 'string'},
            {name: 'markerid', type: 'integer'}
        ],
        listeners: {
            'load': function() {
                Ext.getCmp('createformTypeCombo').getStore().filter('markerid', 17);
            }
        }
    });


    var form = new Ext.form.FormPanel({
        renderTo: Ext.getBody(),
        items: [
            new Ext.form.Label({
                text: "form",
                margin: "25 10 25 5"
            }),
            new Ext.form.ComboBox({
                fieldLabel: 'Marker',
                id: 'createformTypeCombo',
                displayField: 'name',
                valueField: 'id',
                mode:'local',
                lastQuery: '',
                store: markerStore
            })
        ]
    });
});

【讨论】:

  • 至于 _('Default') - 可以忽略它,删除 _() - 这些是翻译脚本的特殊标签。 bindStore 也是私有的(默认情况下文档不显示它)。我无法将过滤器添加到加载事件,因为最终过滤器值是动态的并且作为函数的参数出现。存储加载一次,然后过滤掉所需的结果 - 以避免对服务器和数据库的过多查询。
  • 好的,如果您尝试在加载事件中添加过滤器,这应该可以解决您的问题,希望如此。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-11-03
  • 2014-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多