0

我正在处理一个需要绑定组合框但它没有重新加载最新数据的显示器。只有一次调用数据库,然后使用缓存中的现有存储。如何让它每次都从数据库重新加载(或者至少每次我们重新打开显示时)。下面是代码。

//store
Ext.define('NetworkStore', {
    extend: 'Ext.data.Store',
    alias: 'NetworkStore',
    fields: ['Id', 'value'],
    storeId: 'NetworkStore', 
    autoLoad: true,
    proxy: {
        type: 'ajax',
        useDefaultXhrHeader: false,
        actionMethods: { create: "POST", read: "GET", update: "POST", destroy: "POST" },
        headers: { 'Content-Type': 'application/x-www-form-urlencode' },
        limitParam: false,
        startParam: false,
        pageParam: false,
        extraParams: {
            Style: 1
        },
        url: 'url',
        reader: {
            type: 'json'
        }
    }
});

xtype: 'combo',
name: 'NetworkIDList',
store: Ext.create('NetworkStore').load({
                    params: {
                        Style: 3
                    }
                }),
4

5 回答 5

1

提供的官方文档lastQuery

    listeners: {
        beforequery: function (qe) {
            delete qe.combo.lastQuery;
        }
    }

这是完整的问题:

/**
 * @property {String} lastQuery
 * The value of the match string used to filter the store. Delete this property to force
 * a requery. Example use:
 *
 *     var combo = new Ext.form.field.ComboBox({
 *         ...
 *         queryMode: 'remote',
 *         listeners: {
 *             // delete the previous query in the beforequery event or set
 *             // combo.lastQuery = null (this will reload the store the next time it expands)
 *             beforequery: function(qe){
 *                 delete qe.combo.lastQuery;
 *             }
 *         }
 *     });
 *
 * To make sure the filter in the store is not cleared the first time the ComboBox trigger
 * is used configure the combo with `lastQuery=''`. Example use:
 *
 *     var combo = new Ext.form.field.ComboBox({
 *         ...
 *         queryMode: 'local',
 *         triggerAction: 'all',
 *         lastQuery: ''
 *     });
 */
于 2019-12-23T21:03:40.183 回答
0

将所需的逻辑添加到列表expand事件处理程序。

小提琴

            xtype: 'combo',
            name: 'NetworkIDList',
            listeners: {
                expand: function () {
                    this.getStore().load()
                }
            },
            store: Ext.create('NetworkStore').load({
                params: {
                    Style: 3
                }
            })
于 2019-12-23T10:14:55.627 回答
0

如果我们通过下面给出的存储,它将始终从数据库而不是缓存中获取存储。

  store: {
            type: 'NetworkStore',
            proxy: {
                    extraParams: {
                        Style: 3
                    }
                }
            }
于 2019-12-24T09:25:20.947 回答
0
remoteFilter: true

如果要在每次扩展组合框时从服务器端加载数据,则为 true;如果您想在加载数据后在本地加载数据,则为 false。

如果存储中未设置 remoteFilter 属性,则默认为 false。soo 将此属性设置为 true 可能会解决问题

于 2019-12-27T06:58:40.733 回答
0

首先,您需要将您的愿望转化为系统逻辑。

“至少每次我们重新打开显示器时”

就像下面的逻辑:

  1. 监听小部件的事件,这意味着“当我们重新打开显示时”
  2. 重新加载小部件的商店
    {
       xtype: 'combo',
       name: 'NetworkIDList',
       store: Ext.create('NetworkStore').load({
                    params: {
                        Style: 3
                    }
                }),
      //Add this:
       afterRender: function(){
            //Just do this to load the store
            this.getStore().load();
       }
     }

afterRender 是可以声明为方法的示例侦听器之一。您可以使用许多其他事件侦听器来放置代码以根据需要一次又一次地加载小部件的商店。

https://docs.sencha.com/extjs/7.0.0/modern/Ext.Widget.html#method-afterRender

.load() 是 ProxyStore 的方法,可用于先手动加载或重新加载存储。

https://docs.sencha.com/extjs/7.0.0/modern/Ext.data.ProxyStore.html#method-load

希望它有所帮助。

于 2019-12-28T16:27:34.343 回答