Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read ExtJS message from ajax store

Tags:

extjs4

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.

like image 312
Marc Avatar asked Nov 02 '11 08:11

Marc


1 Answers

use store load event:

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

UPDATE

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: {
  // ...
like image 150
Molecular Man Avatar answered Oct 06 '22 16:10

Molecular Man