Extjs4 - Ajax Request : Url generation

牧云@^-^@ 提交于 2020-01-17 01:22:05

问题


I need to set an ajax request with a generated url.

Ext.define('Cc.store.Absences', {
    extend: 'Ext.data.Store',
  model: 'Cc.model.Absence',
  autoLoad: false,
  proxy: {
    type: 'ajax',
    url:  'person/user_id/absences', //I need a param to define user id 
    reader: {
      type: 'json'
    }
  }
});

I think I have to use Ext.data.Operation but I don't know how to do that.


回答1:


If you are looking to dynamically generate an URL and assign it to the store, you can do it as follows:

store.getProxy().url = '/person/' + user_id +'/absences';
store.load(); // need to reload your store.

To pass as normal parameters (POST or GET methods), you can use the technique explained by Warung Nasi.

You can use Ext.data.Operation if you plan generate parameters automatically for sorting, filtering , grouping etc to your store's proxy. You can read about the possible parameters in Ext.data.proxy.Ajax documentation. Refer the Url Generation sub heading.




回答2:


use extraParams more info

Ext.define('Cc.store.Absences', {
   extend: 'Ext.data.Store',
   model: 'Cc.model.Absence',
   autoLoad: false,
   proxy: {
     type: 'ajax',
     extraParams : {
        id : "123"
     },
     url:  'person/user_id/absences', //I need a param to define user id 
     reader: {
       type: 'json'
     }
   }
});


来源:https://stackoverflow.com/questions/6056551/extjs4-ajax-request-url-generation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!