Results 1 to 2 of 2

Thread: How to override a method when defining an object by using its xtype/alias

  1. #1
    Touch Premium Member
    Join Date
    Aug 2010
    Location
    New York, NY
    Posts
    66
    Answers
    2
    Vote Rating
    1
      0  

    Default Answered: How to override a method when defining an object by using its xtype/alias

    Hi,

    I am defining a writer object like this:

    Code:
    writer:{
      type: 'json'
      rootProperty: 'resources'
      getRecordData: function(rec){
        alert("i was here");
        return rec.data;
      }
    }
    In this code getRecordData is never run and my alert is never fired.

    Now i have also learned that having my own class which extende the Ext.data.reader.Json and then using its alias in my code would work. All i do then is define
    getRecordData
    outside the config object in my class.

    So my question is how to define my own methods when i am instantiating an object in the style I have given above?

    Thanks

  2. When specifying any config to create an instance with, you should not define a method as it will not get overridden. If you need to override a method, you should then extend the class and override it that way.

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

    Default

    When specifying any config to create an instance with, you should not define a method as it will not get overridden. If you need to override a method, you should then extend the class and override it that way.
    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

Tags for this Thread

Posting Permissions

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