2011-05-19 60 views
0

我需要使用生成的url设置ajax请求。Extjs4 - Ajax请求:网址生成

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' 
    } 
    } 
}); 

我想我必须使用Ext.data.Operation,但我不知道该怎么做。

回答

0

如果您正在寻找动态生成的URL,并将其分配到店里,你可以如下做到这一点:

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

要通过正常的参数( POST或GET方法),你可以使用Warung Nasi解释的技术。

如果您计划自动生成参数用于排序,过滤,分组等等到您的商店的代理,您可以使用Ext.data.Operation。您可以阅读Ext.data.proxy.Ajax documentation中的可能参数。请参阅Url生成子标题。

+0

完美,这就是我需要的。谢谢=) – 2011-05-19 13:57:35

3

使用extraParamsmore 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' 
    } 
    } 
}); 
+0

但在我的控制器中,我必须做些什么来改变这个参数? – 2011-05-19 12:33:27

+0

实际上,这个ajax调用将返回用户的缺席。我需要更改根据用户调用的网址。 – 2011-05-19 13:02:24