如何设置extraParams存储extjs的动态值



我有一个问题,在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]
},
},

i got errorundefined..

my full store code

Ext.define('Admin.store.npk.mdm.LayananAlat', {
extend: 'Ext.data.Store',
alias: 'store.layananalat',
requires: [
'Config'
],
autoLoad: true,
proxy: {
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
}
}
},
listeners: {
load: function (store, records, success) {
console.log(Ext.ComponentQuery.query('combobox[reference=terminal2]')[0])
}
}
});

或者有另一种方法传递动态值到extraParamsproxy存储在extjs?

您的代理设置将在构建阶段设置,此时最有可能您的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();

最新更新