extjs-使用来自数据库(sql)的另一个组合框的值填充组合框

57hvy0tb  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(331)

我有两个组合框,值来自我使用json填充的数据库。第二个组合在第一个组合更改时填充。当我们第一次设置第一个组合的值时,它就像魔法一样工作。但第二次,它没有得到绑定。并抛出一个错误这是我的运行代码:

<script type="text/javascript">
Ext.onReady(function() {

 var serverStore = Ext.create('Ext.data.Store', {
  storeId: 'serverStore',
  fields: [
   {
    name: 'u_hostname',
    mapping: 'u_hostname',
    type: 'string'
   }
  ],
  proxy: {
   type: 'ajax',
   url: '/list/data/dbapi/getRecordData',
   extraParams: {
    type: 'table',
    useSql: true,
    sqlQuery: 'select distinct(u_hostname) from SCRIPT_SCHEDULE'
   },
   reader: {
    type: 'json',
    root: 'records'
   }
  },
  autoLoad: true
 });

 var dpsStore = Ext.create('Ext.data.Store', {

  storeId: 'dpsStore',
  fields: [
   {
    name: 'u_username',
    mapping: 'u_username',
    type: 'string'
   },
   {
    name: 'u_hostname',
    mapping: 'u_hostname',
    type: 'string'
   }
  ],
  proxy: {
   type: 'ajax',
   url: '/list/data/dbapi/getRecordData',
   extraParams: {
    type: 'table',
    useSql: true,

   },
   reader: {
    type: 'json',
    root: 'records'
   }
  },
  autoLoad: true
 });

    var dpsCombo = Ext.create('Ext.form.ComboBox',{
    id: 'dpsCombo',
    fieldLabel: 'Username',
    hidden: false,
    margin: '5 0 0 25',
    queryMode: 'local',
    valueField: 'u_username',
    displayField: 'u_username'

    });

   var serverCombo = Ext.create('Ext.form.ComboBox',{
    id: 'serverCombo',
    fieldLabel: 'Server Name',
    hidden: false,
    margin: '5 0 0 25',    
    store: serverStore,
    queryMode: 'local',
    valueField: 'u_hostname',
    displayField: 'u_hostname',
   listeners: {               
        change: changeStore
   }
});
    function changeStore(combo, value){
        var store;
        store = dpsStore;
        var combobox = Ext.getCmp('dpsCombo');
        combobox.clearValue();
        console.log(value);
        store.getProxy().setExtraParam("sqlQuery", `select distinct(u_username) from SCRIPT_SCHEDULE where u_hostname ='${value}'`);
        console.log(value);
        combobox.bindStore(store);
        store.load();

}

 Ext.create('Ext.container.Viewport', {
  id: 'processviewport',
  layout: 'border',
  items: [{
   xtype: 'panel',
   id: 'filterPanel',
   layout: 'hbox',
   title: 'Data filter',
   region: 'north',
   collapsible: true,
   items: [{
    xtype: 'panel',
    layout: 'hbox',
    flex: 2,
    items:[
     {
     xtype: 'panel',
     layout: 'vbox',
     items: [
      serverCombo,
      dpsCombo
     ]
    }]
   }]
  }]
 });
});

</script>

错误:
未捕获的typeerror:无法读取未定义的属性“call”

sauutmhj

sauutmhj1#

通过在第二个组合框中添加lastquery:字段,解决了组合框未呈现第二个更改的数据的问题。

相关问题