Results 1 to 4 of 4

Thread: Load data from REST where response is string

  1. #1
    Sencha User
    Join Date
    Jan 2013
    Location
    Salvador, Bahia - Brazil
    Posts
    35
    Vote Rating
    0
      0  

    Default Unanswered: Load data from REST where response is string

    Hello guys.
    I defined a view that extends from Ext.List. I created a store and a Model for this.

    My Store:
    Code:
    Ext.define('ConnectMobile.store.Groups', {
        extend: 'Ext.data.Store',
        requires: [
            'Ext.data.proxy.Ajax'
        ],
        config: {
            model: 'ConnectMobile.model.Groups',
            autoLoad: true,
            proxy: {
                type: 'ajax',
                url: 'url of the REST server',
                actionMethods: {
                    read: 'POST'
                },
                reader: {
                    type: 'json',
                    rootProperty: 'result',
                }
            }
        }
    });
    My Model:
    Code:
    Ext.define('ConnectMobile.model.Groups', {
        extend: 'Ext.data.Model',
        
        config: {
            clientIdProperty: 'guid',
            fields: [
                {name: 'guid', type: 'int'},
                {name: 'owner_guid', type: 'int'},
                {name: 'container_guid', type: 'int'},
                {name: 'access_id', type: 'int'},
                {name: 'name', type: 'string'},
                {name: 'picture', type: 'string'}
            ]
        }
    });
    My Ext.List view:
    Code:
    Ext.define('ConnectMobile.view.GroupsList', {
        extend: 'Ext.List',
        xtype: 'connectgroupslist',
        config: {
            itemCls: 'groups-list-item',
            // This is a test template
            itemTpl: '<div class="connect-left"><span class="title">{name}</span><span class="status">Open</span></div><div class="connect-right activity">2</div>',
            store: 'Groups',
            layout: 'fit'
        }
    });
    My ContainerPanel:
    Code:
    Ext.define('ConnectMobile.view.GroupsContainer', {
        extend: 'Ext.navigation.View',
        xtype: 'connectgroupscontainer',
        requires: ['ConnectMobile.view.GroupsList'],
        config: {
            fullscreen: true,
            navigationBar : {
                docked : 'top',
                items : [
                    {
                        text : 'Sair',
                        align : 'right',
                        handler: function (obj) {
                            obj.up('connectgroupscontainer').onLogoutButtonTap();
                        },
                        scope: this
                    }
                ]
            },
            items: [
                {
                    title: 'Grupos',
                    xtype: 'connectgroupslist'
                }
            ]
        }
    });
    My listview is in a ContainerPanel.
    My problem is that my proxy Store is a rest and returns:
    Code:
    {
         status: int,
         result: json string
    }
    When I define rootProperty: 'result', the data is not loaded in Store.
    What should I do to load the Store data correctly?
    The result comes like this:
    Code:
    {
         data:
         {
             error: bool,
             errorMsg: string,
             total: int,
             groups: array
         }
    }
    The data I need are in result.data.groups, but result is a string

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,411
    Answers
    3898
    Vote Rating
    1290
      0  

    Default

    So it's like this:

    Code:
    {
        status : 1,
        result : '[...]'
    }
    and not

    Code:
    {
        status : 1,
        result : [...]
    }
    Notice the quote in the first one.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

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

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Jan 2013
    Location
    Salvador, Bahia - Brazil
    Posts
    35
    Vote Rating
    0
      0  

    Default

    Exactly, it's a string, not an array neither a json

  4. #4
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,411
    Answers
    3898
    Vote Rating
    1290
      0  

    Default

    It's thinking it's a string, it really has to be an array to work
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

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

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

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
  •