Results 1 to 5 of 5

Thread: Reference instance function/variable inside a store refresh event

  1. #1
    Sencha User
    Join Date
    Nov 2011
    Posts
    72
    Answers
    3
    Vote Rating
    2
      0  

    Default Answered: Reference instance function/variable inside a store refresh event

    I have a controller in which I initialize a store for my view. Now when the store is loaded, I want to apply a function to each record with the each method of the store, so I'm binding on refresh event (which is properly called), however, this does not point to the right scope and I don't this how to call a function of my controller singleton and reference a instance variable of my controller.
    Thanks for any pointer.
    Code:
    getMyStore:function () { // Method of my controller, loading the store from the launch method.
            return Ext.create('Ext.data.Store', {
                model:'My.model.Bean',
                sorters:'date',
                proxy:{
                    type:'ajax',
                    url:'app/resources/data/some_data.json',
                    reader:{
                        type:'json',
                        rootProperty:'root'
                    }
                },
                autoLoad:true,
                listeners:{
                    refresh: function(){
                        this.calcForEach(this); // This is the method of my controller
                        console.log('Store length : ' + store.getCount());
                    }
                }
            });
        }

  2. Code:
    listeners : {
        scope : this,
        refresh : function() {...} //scope is of this which should be the controller
    }

  3. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3932
    Vote Rating
    1272
      0  

    Default

    The first argument in a refresh event is the store.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  4. #3
    Sencha User
    Join Date
    Nov 2011
    Posts
    72
    Answers
    3
    Vote Rating
    2
      0  

    Default

    I'm looking for a pointer to my controller, not to my store...

  5. #4
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3932
    Vote Rating
    1272
      0  

    Default

    Code:
    listeners : {
        scope : this,
        refresh : function() {...} //scope is of this which should be the controller
    }
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  6. #5
    Sencha User
    Join Date
    Nov 2011
    Posts
    72
    Answers
    3
    Vote Rating
    2
      0  

    Default

    Nice, I'll try that. Thanks !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •