问题描述
嗨,我在 extjs 上将动态值存储到 extraParams
时遇到问题..
我的情况是当我在这里console
时我可以从我的组件中获得价值:
listeners: {
load: function (store,records,success) {
console.log(Ext.ComponentQuery.query('comboBox[reference=terminal2]')[0])
}
}
我从该组件获得了值,但是当我尝试将其传递给 extraParam
时出现错误 undefined
..
proxy: {
type: 'ajax',url: Config.getApi() + 'api/public/index',extraParams: {
dParams: Ext.ComponentQuery.query('comboBox[reference=terminal2]')[0]
},},
我收到错误 undefined
..
我的完整商店代码
Ext.define('Admin.store.npk.mdm.LayananAlat',{
extend: 'Ext.data.Store',alias: 'store.layananalat',requires: [
'Config'
],autoLoad: true,proxy: {
type: 'ajax',actionMethods: {
read: 'POST'
},paramsAsJson: true,timeout: 120000,extraParams: {
dParams: Ext.ComponentQuery.query('comboBox[reference=terminal2]')[0]
},headers: {
'token': Ext.util.Cookies.get('Tokens')
},reader: {
type: 'json',rootProperty: function (obj) {
return obj.result
},totalProperty: function (obj) {
return obj.count
}
}
},listeners: {
load: function (store,success) {
console.log(Ext.ComponentQuery.query('comboBox[reference=terminal2]')[0])
}
}
});
或者是否有另一种方法可以将动态值传递给 extjs 中 extraParams
存储中的 proxy
?
解决方法
您的代理设置将在构建阶段设置,此时您的 UI 很可能未构建,因此您的组件查询无法返回引用的 UI 元素。
关闭 autoLoad
并从存储定义中删除代理部分。然后在可以确定 UI 已经构建好的地方设置代理。例如。在视图的 show/painted 事件中,您可以添加像
const store = Ext.getStore('layananalat');
store.setProxy({
type: 'ajax',url: Config.getApi() + 'api/public/index',actionMethods: {
read: 'POST'
},paramsAsJson: true,timeout: 120000,extraParams: {
dParams: Ext.ComponentQuery.query('combobox[reference=terminal2]')[0]
},headers: {
'token': Ext.util.Cookies.get('Tokens')
},reader: {
type: 'json',rootProperty: function (obj) {
return obj.result
},totalProperty: function (obj) {
return obj.count
}
});
store.load();