动态存储不在组合框 extjs 中加载数据

Dynamic store not loading data in combo box extjs

我有两个组合框,例如组合 1 和组合 2,其中填充了两个不同的商店(例如商店 1 和商店 2)。 combo2 中的值取决于在组合 1 中选择的内容。然后我查询服务器以获取 combo2 的数组。换句话说,我在 combo1 中的选择决定了 combo2 的值。 我设置的代码无法正常工作,并给我一个非常普遍的错误 Error: Object doesn't support this action。我在浏览器调试器中看到 return 值,所以我知道这不是我的 ajax 请求。我想我在组合框中遗漏了一些小东西,使值无法显示。请查看下面的代码以获得更好的想法

   var store1 = Ext.create('Ext.data.ArrayStore', {
  model: 'store1model',
  autoLoad: true,
  autoDestroy: true,
  proxy: {
    type: 'ajax',
    url: 'backend.java'
    extraParams: {
      'param1': param1
    },
    reader: {
      type: 'json'
    }
  }
});

var store2 = Ext.create('Ext.data.ArrayStore', {
  model: 'store2model',
  autoLoad: true,
  autoDestroy: true,
  storeId: 'store2Id',
  proxy: 'memory',
  readre: {
    type: 'json'
  }
});

var panel = Ext.create('Ext.form.Panel', {
  title: 'Panel',
  id: 'PanelId',
  url: 'backened.java',
  method: 'GET',
  items: [{
    xtype: container,
    layout: 'column',
    items: [{
      xtype: 'container',
      columnWidth: .5,
      layout: 'anchor',
      items: [{
        xtype: 'combobox',
        fieldLabel: 'Combo1',
        name: 'Combo1',
        store: store1,
        displayField: 'name',
        valueField: 'name',
        anchor: '96%',
        listeners: {
          select: function(combo, records) {
            Ext.Ajax.request({
              url: 'backend.java',
              method: 'GET',
              params: {
                "param2": combo.getValue()
              },
              success: function(response) {
                var data = Ext.Msg.decode(response.responseText);
                store2.loadData(data);
              }
            });
          }
        }
      }, {
        xtype: 'combobox',
        fieldLabel: 'Combo2',
        name: 'Combo2',
        id: 'Combo2',
        store: store2,
        displayField: 'someField',
        valueField: 'someField'

      }]

    }]
  }]


});

经过一些搜索我发现可能我必须在 combo2 中监听事件变化。不确定这是否正确,如果正确,那将如何工作?所以我想我的问题有两个方面。首先,为什么上面的代码不起作用?其次,是否有一种 better/more 优雅的方式来做到这一点。

编辑

 var store2 = Ext.create('Ext.data.ArrayStore', {
   model: 'store2model',
   autoLoad: true,
   autoDestroy: true,
   storeId: 'store2Id',
    proxy: {
     type: 'ajax',
     url: 'backend.java'
   //  extraParams: {
     //  'param2': param2
    // },
     reader: {
       type: 'json'
     }

   }
 });

看起来您为 store1 分配了一个代理,以便您可以执行 store1.load(),也许尝试对 store2 执行相同的操作。

So you could assign the url 'backend.java' as a proxy to store2, and when combo1 gets selected, you can load the store for combo2 with the value is a param.

  {
        xtype: 'combobox',
        fieldLabel: 'Combo1',
        name: 'Combo1',
        store: store1,
        displayField: 'name',
        valueField: 'name',
        anchor: '96%',
        listeners: {
          select: function(combo, records) {
            Ext.getCmp('Combo2').getStore().load({
                params: {
                  param2: combo.getValue()
                }
            });  
          }
        }
      },

这将使用 param2 参数加载 combo2 的商店。因此,无论代理 url 是什么,只需分配 combo2 的商店即可。也许试试看?