admin管理员组

文章数量:1406308

I have the following code, but it is not working. The callback never fires, and so is load listener.

var someDS = new Ext.data.Store({
    proxy : new Ext.data.HttpProxy({url : 'someUrl', method : 'GET'}),
    reader: new Ext.data.JsonReader({} ['aaa', 'bbb', 'ccc']),
    callback : function(options, success, response) {
         alert(response);
         // some code
    },
    listeners: {
         load : function() {
            alert("load");
            // some code
         }
     }
});

I have the following code, but it is not working. The callback never fires, and so is load listener.

var someDS = new Ext.data.Store({
    proxy : new Ext.data.HttpProxy({url : 'someUrl', method : 'GET'}),
    reader: new Ext.data.JsonReader({} ['aaa', 'bbb', 'ccc']),
    callback : function(options, success, response) {
         alert(response);
         // some code
    },
    listeners: {
         load : function() {
            alert("load");
            // some code
         }
     }
});
Share Improve this question edited Nov 2, 2019 at 17:29 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Dec 27, 2010 at 23:36 fastcodejavafastcodejava 41.2k31 gold badges139 silver badges191 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

your reader definition doesn't look correct to me: is the "{} ['aaa','bbb','ccc']" bit fine?

anyway, this code works with extjs 3.2:

var mystore = new Ext.data.Store({
    url: '/your/url/',
    autoLoad: true,
    reader: new Ext.data.JsonReader({
        root: 'rows',
        fields: [ 'id', 'field1', 'field2' ]
    }), 
    listeners: {
        load: function(t, records, options) {
            console.log('test ok');
            for (var i=0; i<records.length; i++) {
                console.log(String.format('record {0} = {1}', i, records[i].data.id));
            }   
        }   
    }   
}); 

it works with the following json string returned by the server call at '/your/url/':

{
    "rows": [
        {
            "id": 17, 
            "field1": "Emiliano", 
            "field2": 1 
        }, 
        {
            "id": 18, 
            "field1": "Luca", 
            "field2": 3 
        }         
    ], 
    "total": 2
}
  • do not confuse the load method and the load event;

  • do not forget the 'root' parameter in the reader definition (well, actually it's not necessary to have the 'test ok' string printed, but without it you won't get the ids printed by the for loop)

本文标签: javascriptCallback is not firing in ExtJs StoreStack Overflow