javascript - 组合框和bindStore的存储过滤

标签 javascript extjs ext3

商店通过单独的函数中的bindStore绑定(bind)到组合框。

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

  loadMarkers: function(store, value){

    store.filter('markerid',17);

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

这个具体示例有两种不同的方式,我尝试过 - 绑定(bind)之前和之后。最后的 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'}
  ])
});

最佳答案

由于上面代码的格式,我假设您正在使用 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
            })
        ]
    });
});

关于javascript - 组合框和bindStore的存储过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27793997/

相关文章:

javascript - 使一个元素相对于另一个元素居中

javascript - 如何从另一个 View 上编写的 JS 代码重定向到 Controller 并与其一起传递 JSON 对象

mysql - 将 MyISAM 表从 Solaris 复制到 Linux

c - 重新使用 inode 字段

javascript - 单击下一个按钮时如何删除 magnific-popup.js 或 css 中的蓝线?

javascript - polymer 2.0建筑构件

javascript - 自动执行嵌套 If 语句和递增计数器——Javascript

extjs - ViewModel 绑定(bind)记录幻象

javascript - HTML 中的制表符空间

linux - 写入文件非常快,覆盖文件需要更长的时间