我有一个带有ajax代理和json阅读器的ExtJS商店:
Ext.create('Ext.data.Store', {
proxy: {
type: 'ajax',
url: '...',
reader: {
type: 'json',
root: 'data',
totalProperty: 'totalCount',
messageProperty: 'message',
successProperty: 'success'
},
...
Run Code Online (Sandbox Code Playgroud)
这是我从服务器获得的:
data: [...]
message: "I want to read this string after the store is loaded"
success: true
totalCount: x
Run Code Online (Sandbox Code Playgroud)
现在我想在加载商店时访问"消息" - 我从哪里获得它?我看了很多,但我找不到一个可以挂钩的地方?代理中唯一的侦听器是异常,这对我没有帮助.
使用商店load活动:
Ext.create('Ext.data.Store', {
listeners: {
'load': function(store, records, successful, operation) {
alert(operation.resultSet.message);
}
},
proxy: {
// ...
Run Code Online (Sandbox Code Playgroud)
UPDATE
似乎加载事件的文档是错误的.正确的参数列表是(store, records, successful)(无操作参数).因此上述解决方案无效.
但是有读者的rawData财产可以帮助:
Ext.create('Ext.data.Store', {
listeners: {
'load': function(store, records, successful) {
alert(store.getProxy().getReader().rawData.message);
}
},
proxy: {
// ...
Run Code Online (Sandbox Code Playgroud)