我正在显示器上,我需要绑定一个组合框,但不会重新加载最新数据。只有一个对数据库的调用,此后它使用缓存中的现有存储。如何每次(或至少每次重新打开显示时)从数据库重新加载它。下面是代码。
//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
}
}),
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: ''
* });
*/
将所需的逻辑添加到列表expand
事件处理程序。
xtype: 'combo',
name: 'NetworkIDList',
listeners: {
expand: function () {
this.getStore().load()
}
},
store: Ext.create('NetworkStore').load({
params: {
Style: 3
}
})
如果我们按如下所示传递存储,它将始终从数据库而不是从缓存中获取存储。
store: {
type: 'NetworkStore',
proxy: {
extraParams: {
Style: 3
}
}
}
remoteFilter: true
将此属性设置为商店