Results 1 to 5 of 5

Thread: How to tell Ext.data.reader.Reader to use state code 200 as successProperty?

  1. #1
    Sencha User SunboX's Avatar
    Join Date
    Mar 2010
    Posts
    238
    Answers
    5
    Vote Rating
    28
      0  

    Question Answered: How to tell Ext.data.reader.Reader to use state code 200 as successProperty?

    Hi, I want to fetch data with JsonP from an foreign Server-API. It returns for success:
    Code:
    {"state":200,"results":[...]}
    and in case of an failure, something like this:
    Code:
    {"state":402,"message":"Please provide a valid ..."}
    Now Ext.data.reader.Reader expects an boolean for successProperty. How will I tell the reader, that all worked fine, if state = 200?

    I think of something like this:
    Code:
    Ext.define('App.model.CoolModel', {    extend: 'Ext.data.Model',
        fields: [
            {name: 'id', type: 'string'},
        ],
        proxy: {
            type: 'jsonp',
            url: 'http://xyz/search/coolapi.json',
            reader: {
                type: 'json',
    
                success: function(data) {
                    return data.state == 200;
                },
    
                root: 'results'
            }
        }
    });
    could someone please point me the right direction? thx Sunny

  2. You will have to override the proxy in the processResponse method. There is a check where result.success !== false, that's where it checks to see if the success property is true/false. So after the result variable get's filled with data from the reader, you will need to set result.success.

  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 successProperty is expecting a boolean value... 200 is truthy in javascript but so is 500 or 402
    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 SunboX's Avatar
    Join Date
    Mar 2010
    Posts
    238
    Answers
    5
    Vote Rating
    28
      0  

    Default

    Yes, makes sense. But how do I tell the reader that response state = 200 is success?

  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

    You will have to override the proxy in the processResponse method. There is a check where result.success !== false, that's where it checks to see if the success property is true/false. So after the result variable get's filled with data from the reader, you will need to set result.success.
    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 SunboX's Avatar
    Join Date
    Mar 2010
    Posts
    238
    Answers
    5
    Vote Rating
    28
      0  

    Thumbs up

    Ah, ok great. 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
  •