Results 1 to 3 of 3

Thread: Rest Proxy and Different Roots for Different Operations (List/Create), autoSync

  1. #1
    Sencha Premium Member
    Join Date
    Aug 2008
    Posts
    88
    Vote Rating
    0
      0  

    Exclamation Rest Proxy and Different Roots for Different Operations (List/Create), autoSync

    How do I configure different 'root' for List (GET) and Add (POST) operations? Extjs 4.2

    Code:
        var store = new Ext.data.TreeStore({
            model: 'folder',
            autoSync: true,
            proxy: {
                type: 'rest',
                url: '/service/folders',
                appendId: true,
                reader: {
                    type: 'json',
                    root: 'subFolders'
                },
                writer: {
                    type: 'json',
                    nameProperty: 'mapping',
                    root: 'folder'
                }
            },
            root: {
                text: 'My Folders',
                id: '1',
                expanded: true
            }
        });
    The service returns, For listing (GET /service/folders/{id})
    Code:
    {
        subFolders[{
            id: 1,
            text: 'Folder A'
        }]
    }
    For creation (POST /service/folders)
    Code:
    {
        folder: {
            id: 10,
            text: 'Folder New'
        }
    }

  2. #2
    Sencha User slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,165
    Answers
    505
    Vote Rating
    255
      0  

    Default

    Instead of using the url config:
    http://docs.sencha.com/extjs/4.2.1/#...y.Rest-cfg-url

    You can use the api config:
    http://docs.sencha.com/extjs/4.2.1/#...y.Rest-cfg-api

    Which will let you set different URLs for each action.

  3. #3
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,791
    Answers
    585
    Vote Rating
    394
      0  

    Default

    There's nothing out-of-the-box for this so I think your best bet would be to override a method on the reader. For example, you could maybe override buildExtractors to create your own getRoot function. There are alternative overrides you could try but that'd be where I'd start.

    The override itself wouldn't need to know what type of request it is. Instead just pull out whichever property is present in the response.

Posting Permissions

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