Results 1 to 10 of 11

Thread: ExtJS Model URL

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sencha User
    Join Date
    Mar 2013
    Posts
    9
    Vote Rating
    2
      0  

    Default ExtJS Model URL

    Hi guys,

    I am trying to implement a GET data from the server, but ExtJs is sending weird url, take a look:
    http://localhost:8098/rest/v1/distribution-list/1?id=1

    It shouldn't send parameter 'id', how can i remove that?

    this is my Model

    Ext.define('Wave.model.DistributionList', {
    extend: 'Ext.data.Model',
    fields: [
    {name: 'id'},
    {name: 'name', type: 'string'},
    {name: 'status', type: 'string'}

    ],

    proxy: {
    type: 'rest',
    noCache: false,
    reader: {
    type: 'json'
    },
    actionMethods: {
    create: 'POST',
    read: 'GET', // defaults to GET
    update: 'POST',
    destroy: 'DELETE'
    },
    api: {
    read: 'http://localhost:8098/rest/v1/distribution-list/',
    create: 'http://localhost:8098/rest/v1/distribution-list/',
    update: 'http://localhost:8098/rest/v1/distribution-list/',
    destroy: 'http://localhost:8098/rest/v1/distribution-list/'
    }

    }
    });

  2. #2
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,050
    Answers
    3976
    Vote Rating
    1382
      0  

    Default

    This has been changed in 4.1.3 and 4.2.0. By default it will not send the id parameter unless you opt in with a config.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  3. #3
    Sencha User
    Join Date
    Mar 2013
    Posts
    9
    Vote Rating
    2
      0  

    Default

    im using 4.2.0, but I did not opt for that.
    how can i remove the 'id=1'?

    cheers

  4. #4
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,050
    Answers
    3976
    Vote Rating
    1382
      0  

    Default

    I'm sorry... guess the config default changed from when it was first talked about. There is an appendId config on the Rest proxy that if you set to false should not send the id parameter.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  5. #5
    Sencha User
    Join Date
    Mar 2013
    Posts
    9
    Vote Rating
    2
      1  

    Default

    I have tried this, if appendId = false, it sends a url like this:
    http://localhost:8098/rest/v1/distribution-list?id=1

  6. #6
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,050
    Answers
    3976
    Vote Rating
    1382
      -1  

    Default

    We were chasing two different things. Remove the appendId config and to get rid of the url parameter you can try this override:

    Code:
    Ext.define('Override.data.proxy.Rest', {
        override : 'Ext.data.proxy.Rest',
    
        buildRequest : function(operation) {
            delete operation.id;
    
            return this.callParent(arguments);
        }
    });
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  7. #7
    Sencha Premium User
    Join Date
    Jun 2011
    Location
    Seattle, WA
    Posts
    31
    Vote Rating
    1
      0  

    Default

    Looks like this is still a bug in 6.2.

    I resolved it by overriding the "buildRequest" method from Ext.data.proxy.Server to remove these lines:

    Code:
    //We comment these lines out to prevent model ids from being sent as query params
    // if (operationId !== undefined && params[idParam] === undefined) {
    //     params[idParam] = operationId;
    // }
    Maybe I'm missing something?

  8. #8
    Sencha User alfonso.nishikawa's Avatar
    Join Date
    Jul 2015
    Posts
    63
    Answers
    1
    Vote Rating
    26
      0  

    Default

    Quote Originally Posted by ithompson View Post
    Looks like this is still a bug in 6.2.

    I resolved it by overriding the "buildRequest" method from Ext.data.proxy.Server to remove these lines:

    Code:
    //We comment these lines out to prevent model ids from being sent as query params
    // if (operationId !== undefined && params[idParam] === undefined) {
    //     params[idParam] = operationId;
    // }
    Maybe I'm missing something?
    You are modifying all requests, whether they are REST, Ajax, Direct or JSONP. I would use an override like the ones in former comments. This is what I would use to remove the ID if appendId is false:

    Code:
    Ext.define('Foo.data.proxy.Rest', {
        override: 'Ext.data.proxy.Rest',
    
        buildUrl: function (request) {
            var me = this ;
    
            if (!me.getAppendId()) {
                params = request.getParams() ;
                if (params) {
                    delete params[me.getIdParam()] ;
                }
            }
    
            return this.callParent(arguments) ;
        }
    }) ;

Posting Permissions

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