1. #1
    Sencha User
    Join Date
    Jan 2013
    Location
    Salvador, Bahia - Brazil
    Posts
    11
    Vote Rating
    0
    luciano.lima is on a distinguished road

      0  

    Default Unanswered: Load data from REST where response is string

    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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,399
    Answers
    3549
    Vote Rating
    849
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      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 @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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
    11
    Vote Rating
    0
    luciano.lima is on a distinguished road

      0  

    Default


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

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,399
    Answers
    3549
    Vote Rating
    849
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    It's thinking it's a string, it really has to be an array to work
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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.