0

ExtJS6 model is not forming correct proxy urls for dynamic parameters

Model looks like

Ext.define('Testt.model.User', {
  extend: 'Ext.data.Model',
  fields: ['id', 'name'],

  proxy: {
   type: 'ajax',
   api : {
    read : 'api/user/:id',
    create : 'api/user',
    update : 'api/user/:id',
    destroy : 'api/user/:id'
   },
   reader : {
    type : 'json'
   },
   writer : {
    type : 'json'
   }
 }
});

Now when called to load a user record like

Testt.model.load(27, { success: function(rec){console.log(rec)}})

It does not replace :id with actual 27

ducktyped
  • 4,354
  • 4
  • 26
  • 38
  • 2
    Where in the ExtJS docs did you find the `:id` syntax? – Alexander Jun 29 '16 at 10:58
  • This syntax is used in Router. But anyhow the question would how we could get Ext.data.Model replace id in proxy dynamically – ducktyped Jun 29 '16 at 11:01
  • 1
    Please provide a link to the ExtJS docs that state that this syntax is correct. Also I cannot find any ExtJS docs that state that you can call load from the model prototype (statically) and provide the id as first parameter. The samples I find say otherwise. – Alexander Jun 29 '16 at 11:14
  • Yes, there is nowhere in the Model documentation that says to do this... Read the doc – Ruan Mendes Jun 29 '16 at 12:03

1 Answers1

4

If you use the REST Proxy type (http://docs.sencha.com/extjs/6.0.1-classic/Ext.data.proxy.Rest.html) then the IDs will be automatically appended to your URLs. You don't need the ':id' syntax in the urls.

Check out this fiddle to see it working: https://fiddle.sencha.com/#fiddle/1cri

Stuart
  • 3,258
  • 4
  • 29
  • 39