问题
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