从Ajax商店读取ExtJS消息 [英] Read ExtJS message from ajax store
问题描述
我有一个带有ajax代理和json阅读器的ExtJS商店:
I have an ExtJS store with an ajax proxy and json reader:
Ext.create('Ext.data.Store', {
proxy: {
type: 'ajax',
url: '...',
reader: {
type: 'json',
root: 'data',
totalProperty: 'totalCount',
messageProperty: 'message',
successProperty: 'success'
},
...
这是我从服务器获得的信息:
This is what I get from the server:
data: [...]
message: "I want to read this string after the store is loaded"
success: true
totalCount: x
现在,我想在商店加载时访问消息"-从哪里获得?我看了很多东西,但是找不到合适的地方吗?代理中唯一的侦听器是例外,对我没有真正的帮助.
Now I want to access the 'message' when the store is loaded - where do I get it? I looked a lot but I can't find a place to hook in? The only listener in the proxy is exception, that doesn't really help me.
推荐答案
use store load
event:
Ext.create('Ext.data.Store', {
listeners: {
'load': function(store, records, successful, operation) {
alert(operation.resultSet.message);
}
},
proxy: {
// ...
更新
看来,加载事件的文档是错误的.正确的参数列表是(store, records, successful)
(无操作参数).因此,上述解决方案不起作用.
It appears that documentation for load event is wrong. The correct list of arguments is (store, records, successful)
(no operation argument). Therefore the solution above wouldn't work.
However there is reader's rawData
property which can help:
Ext.create('Ext.data.Store', {
listeners: {
'load': function(store, records, successful) {
alert(store.getProxy().getReader().rawData.message);
}
},
proxy: {
// ...
这篇关于从Ajax商店读取ExtJS消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!