2014-09-01 81 views
0

我對Ember很新,所以希望我只是在做一些愚蠢的事情,但我一直在遇到很多隨機問題,數據顯示不正確,現在我在Ember Debugger中看到我的數據不存在,直到我打到特定的模型數據端點。舉例來說,我有一個模板來顯示所有的產品,這裏的路線:Ember DjangoRESTAdapter數據未加載

App.ProductsRoute = Ember.Route.extend({ 
    model: function() { 
     return this.store.find('product'); 
    } 
}); 

控制器:

App.ProductsController = Ember.ArrayController.extend({ 
    itemController: 'product' 
}); 

模板:

<script type="text/x-handlebars" data-template-name="products"> 
    <div class="row"> 
     {{#each}} 
      {{name}} 
     {{/each}} 
    </div> 
</script> 

擊中端點 '/產品'如果我去'/ products/1',我可以在視圖(和Ember調試器)中看到產品數據,然後如果我回到'/ products'那個特定產品的數據(但沒有其他數據)正確顯示。所以我對我做錯了什麼感到困惑。正如標題所暗示的,我使用的是DjangoRESTAdapter如果這有助於縮小東西下來,這裏是我的app.js以及提前任何幫助

window.App = Ember.Application.create({}); 
window.api_location = 'http://localhost:8000/api'; 


App.ApplicationAdapter = DS.DjangoRESTAdapter.extend({ 
    host: api_location, 
    pathForType: function(type) { 
     return Ember.String.underscore(type); 
    } 
}); 
App.ApplicationSerializer = DS.DjangoRESTSerializer.extend({ 
}); 

App.Store = DS.Store.extend(); 

感謝,讓我知道,如果其他代碼段會有所幫助。

回答

0

好的,我終於明白了這一點:這是一個分頁問題。我沒有意識到我們爲我們的Django REST API設置了分頁,所以它不是返回一個對象列表,而是返回一個結果對象,並將產品列表隱藏在「結果」屬性中。所以直到我能說服其他開發者關閉分頁我可以修改我的所有查詢:

this.store.find('product', {page_size:0}); 

覆蓋我們的默認頁面大小。

編輯:我也嘗試修改服務器端的json響應,而不是使用djangorestadapter與此庫:https://github.com/ngenworks/rest_framework_ember。希望這可以節省一些人的一些挖掘...