0

商店在单独的函数中使用 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'}
  ])
});
4

1 回答 1

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
            })
        ]
    });
});
于 2015-01-06T11:38:52.390 回答