Reading ExtJS message from ajax repository

I have ExtJS repository with 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 loading the store - where will I get it? I watched a lot, but I can’t find a place to catch on? The only listener in the proxy server is the exception, which does not really help me.

+6
source share
4 answers

use storage load event:

 Ext.create('Ext.data.Store', { listeners: { 'load': function(store, records, successful, operation) { alert(operation.resultSet.message); } }, proxy: { // ... 

UPDATE

The documentation for the download event seems to be incorrect. The correct argument list (store, records, successful) ( no operation argument ). Therefore, the solution above will not work.

However, there is a reader rawData property that can help:

 Ext.create('Ext.data.Store', { listeners: { 'load': function(store, records, successful) { alert(store.getProxy().getReader().rawData.message); } }, proxy: { // ... 
+5
source

My answer relates to ExtJs 4.1.x. I spent some time reading the code, and it seems like one way to do this is to provide a callback in the store's beforelload event instead of handling the load event. The callback is transmitted by the operation object, which will contain the initial request parameters, and if successful, it will contain the response object and data (analyzed) in the resultSet property.

0
source

Otherwise:

 myStore.load({ callback : function(object, response, success) { // on error response: success = false if(!success) { // i don't remember de correct path to get "message" or "responseText" console.log(response.response.responseText); } else { ... } }); 

Cya!

0
source

I get the message as follows, although I load manually and do not use events here:

 var initData = Ext.create('My.data.SomeAjaxStore'); initData.load(function(records, operation, success) { if (!success || operation.hasException()) { // Here is your message from server // In case of HTTP error you get: // { // status: 404, // statusText: "Not Found" // } var error = operation.getError(); Ext.log({msg:[Ext.getClassName(me), ": Command failure: ", error].join(""), level:"error"}); } 
0
source

Source: https://habr.com/ru/post/900585/


All Articles