2014-02-26 86 views
0

我試圖創建一些路由,從我的模型(基於布爾值)篩選出批准和拒登的照片。Ember.js錯誤:對象沒有方法'eachRelatedType'

這是我的主要photosapproveddisapproved路線:

# router.js 
App.Router.map -> 
    @resource "photos", -> 
    @resource "photo", 
     path: ":photo_id" 
    # additional child routes 
    @route "approved" 
    @route "disapproved" 

# photos_routes.js 
App.PhotosRoute = Ember.Route.extend(
    model: -> 
    App.Photo.find() 
) 

App.PhotosApprovedRoute = Ember.Route.extend(
    model: -> 
    @store.filter "Photo", {approved: true}, (photo) -> 
     photo.get("approved") 
    renderTemplate: -> 
    @render "photos" 
    @render controller: "PhotosController" 
) 

App.PhotosDisapprovedRoute = Ember.Route.extend(
    model: -> 
    @store.filter "Photo", {approved: false}, (photo) -> 
     not photo.get("approved") 
    renderTemplate: -> 
    @render "photos" 
    @render controller: "PhotosController" 
) 

這裏是我的photo.js型號:

App.Photo = DS.Model.extend(
    name: DS.attr("string") 
    description: DS.attr("string") 
    image_url: DS.attr("string") 
    approved: DS.attr("boolean") 
) 

最後,我application.hbsphotos.hbs模板:

{{!-- application.hbs --}} 
<header id="header"> 
    <h2>{{#link-to "index"}}Home{{/link-to}}</h2> 

    <nav> 
    <ul> 
     <li>{{#link-to "photos"}}All photos{{/link-to}}</li> 
     <li>{{#link-to "photos.approved"}}Approved{{/link-to}}</li> 
     <li>{{#link-to "photos.disapproved"}}Disapproved{{/link-to}}</li> 
    </ul> 
    </nav> 
</header> 

<div id="content"> 
    {{outlet}} 
</div> 

{{!-- photos.hbs --}} 
<h1>Photos</h1> 

<ul> 
    {{#each controller}} 
    <li class="masonry-brick"> 
     <img {{bind-attr src=image_url}} alt="Logo"> 
    </li> 
    {{else}} 
    <li>There are no photos.</li> 
    {{/each}} 
</ul> 

{{outlet}} 

當我點擊鏈接,對無論是photos.approved或,我得到控制檯以下錯誤:

TypeError: Object Photo has no method 'eachRelatedType' 
Uncaught Error: Assertion Failed: TypeError: Object Photo has no method 'eachRelatedType' 

完整堆棧跟蹤:

TypeError: Object Photo has no method 'eachRelatedType' 
    at DS.JSONSerializer.DS.Serializer.extend.configureSideloadMappingForType (http://localhost:3000/assets/ember-data.js?body=1:7798:10) 
    at DS.JSONSerializer.DS.Serializer.extend.sideload (http://localhost:3000/assets/ember-data.js?body=1:7768:10) 
    at DS.JSONSerializer.DS.Serializer.extend.extractMany (http://localhost:3000/assets/ember-data.js?body=1:7692:10) 
    at superWrapper [as extractMany] (http://localhost:3000/assets/ember.js?body=1:1240:16) 
    at DS.Adapter.Ember.Object.extend.didFindQuery (http://localhost:3000/assets/ember-data.js?body=1:8329:29) 
    at http://localhost:3000/assets/ember-data.js?body=1:9912:15 
    at invokeCallback (http://localhost:3000/assets/ember.js?body=1:9754:19) 
    at publish (http://localhost:3000/assets/ember.js?body=1:9424:9) 
    at Promise.publishFulfillment (http://localhost:3000/assets/ember.js?body=1:9844:7) 
    at Object.DeferredActionQueues.flush (http://localhost:3000/assets/ember.js?body=1:5894:24) 
    at Object.Backburner.end (http://localhost:3000/assets/ember.js?body=1:5985:27) ember.js?body=1:3462 
Uncaught Error: Assertion Failed: TypeError: Object Photo has no method 'eachRelatedType' ember.js?body=1:74 
Ember.assert ember.js?body=1:74 
Ember.RSVP.onerrorDefault ember.js?body=1:16899 
__exports__.default.trigger ember.js?body=1:8718 
Promise._onerror ember.js?body=1:9442 
publishRejection ember.js?body=1:9849 
DeferredActionQueues.flush ember.js?body=1:5894 
Backburner.end ember.js?body=1:5985 
Backburner.run ember.js?body=1:6024 
Ember.run ember.js?body=1:6427 
hash.success ember-data.js?body=1:10004 
fire jquery.js?body=1:3049 
self.fireWith jquery.js?body=1:3161 
done jquery.js?body=1:8236 
callback 
+0

您可以共享網絡請求響應正文嗎?似乎問題出在您收到的數據上 –

回答

2

對不起,我不應該評論回答。您的堆棧跟蹤發生在您的自定義串行器中。您應該發佈該代碼,因爲這是錯誤所在。

但是,考慮到錯誤,並且eachRelatedType是一個靜態方法,而不是實例方法,所以很可能是您在實例上調用它。請致電photo.constructor.eachRelatedType()App.Photo.eachRelatedType()代替photo.eachRelatedType()

編輯:它似乎你沒有自定義序列化程序。但Ember-Data從來不會調用eachRelatedType,它只是定義它。你使用的是什麼版本的Ember-Data?

EDIT2:看來這個特殊問題是通過從Ember-Data 0.14升級來解決的。雖然沒有確切的原因是已知的。 (可能是Ember-Data錯誤。)

+0

是的,這是一個奇怪的問題,因爲任何對此錯誤的搜索都不會返回任何相關的內容。我的餘燼數據是'version:v0.14' – gosseti

+1

這就是爲什麼。 '0.14'已經很老了(6個月)。任何機會,你可以升級到最新的測試版?如果沒有,我認爲你將不得不重現這是一個JSBin爲我們真正的幫助。我對Ember-Data的內部工作非常熟悉,但沒有任何舊版本。 – GJK

+0

啊,那是問題之一。我現在升級並刷新了硬盤,但是'/ approved'和'/ rejected'路徑現在顯示所有照片。這是否與我上面的'renderTemplate'函數有關? – gosseti

相關問題