2011-05-19 58 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