1. #1
    Sencha User
    Join Date
    Aug 2012
    Posts
    1
    Vote Rating
    0
    tjen67 is on a distinguished road

      0  

    Default How do I get the values from a Sencha JsonP response?

    How do I get the values from a Sencha JsonP response?


    I am new to Sencha touch am having trouble getting the values from a Sencha jsonp request. This is for a mobile application's login screen.

    Here is my controller.

    Ext.define('MyApp.controller.Main', {
    extend: 'Ext.app.Controller',

    refs: [
    {
    ref: 'loginForm',
    selector: '#loginForm'
    }
    ],

    init: function() {
    this.control({
    'button[action=submitLogin]': {
    tap: 'submitLoginForm'
    }
    });},

    submitLoginForm: function() {
    var form = this.getLoginForm();
    Ext.define('Login', {
    extend: 'Ext.data.Model',
    fields: ['id', 'username', 'email']
    })

    var store = Ext.create('Ext.data.Store', {
    model: 'Login',
    proxy: {
    type: 'jsonp',
    url: 'http://some-url/auth.php',
    appendId: true,
    limitParam: false,
    enablePagingParams: false,
    startParam: false,
    },
    reader: {
    type: 'json',
    rootProperty: 'user'
    }
    })
    },
    });

    Once the submit button is tapped everything works fine but I'm not sure how to get the values in the json string. Below is the json.

    Ext.data.JsonP.callback1({"user":[{"id":"1","username":"me","email":"some@thing.com"}]});

    Any help would be appreciated.

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,884
    Vote Rating
    440
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    The values will be added to the store. You can then use:

    Code:
    store.each(function(record) {
       record.get('field');
    }):
    Scott.

Thread Participants: 1

Tags for this Thread