2014-02-21 26 views
0

我有視頻模式,我回來links PARAM指向related URL從API JSON響應:如何將查詢參數傳遞給DS.RestAdapter#findHasMany所做的請求?

video: { 
    id: 1, 
    name: "Whatever", 
    links: { 
    related: "/videos/1/related" 
    } 
} 

,並在Video模型related: hasMany('video', {async: true, inverse: null})關聯。致電video.get('related')/videos/:id/related發出請求。這部分工作正常。

如何將查詢參數傳遞給ajax請求,例如添加分頁參數?我想提出如/videos/:id/related?per=3&page=5的要求。

回答

0

遇到這個,看到這一直沒有答案 - 不知道原始海報是否找到了解決辦法。做到這一點的方法是重寫RESTAdapter的ajax調用 - 我相信會有更好的方法來處理分頁,但這是發送額外參數需要做的事情。

App.VideoAdapter = DS.RESTAdapter.extend({ 
    host: HOST, 
    // Overriding ajax request to include account_id as a parameter 
    ajax: function(url, type, hash) { 
     if (Ember.isEmpty(hash)) hash = {}; 
     if (Ember.isEmpty(hash.data)) hash.data = {}; 
     hash.data.per = App.per; // Global variable - Not the smartest thing to do and should do something else 
     hash.data.page = App.page; // Global variable - Not the smartest thing to do and should do something else 
     return this._super(url, type, hash); 
    } 
}); 
相關問題