Ember.js错误:“对象照片"没有方法' eachRelatedType' [英] Ember.js error: Object Photo has no method 'eachRelatedType'

查看:72
本文介绍了Ember.js错误:“对象照片"没有方法' eachRelatedType'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一些路线,以从模型中过滤出批准和不批准的照片(基于布尔值).

I’m trying to create some routes that filter out approved and disapproved photos from my model (based on a boolean value).

这是我的主要照片已批准未批准的路线:

Here’s my main photos, approved and disapproved routes:

# 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.hbs photos.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 photos.disapproved 上的链接时,在控制台中出现以下错误:

When I click the link-to on either the photos.approved or photos.disapproved, I get the following errors in console:

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

推荐答案

对不起,我不应该在评论中回答.您的堆栈跟踪发生在您的自定义序列化程序中.您可能应该发布该代码,因为这就是错误所在.

Sorry, I shouldn't answer in comments. Your stack trace happens in your custom serializer. You should probably post that code, as that's where the error lies.

但是考虑到错误以及 eachRelatedType 是静态方法而不是实例方法的事实,很可能您是在实例上调用它.代替 photo.eachRelatedType(),而是调用 photo.constructor.eachRelatedType() App.Photo.eachRelatedType().

But given the error, and the fact that eachRelatedType is a static method, not an instance method, it's likely that you're calling it on an instance. Instead of photo.eachRelatedType(), call photo.constructor.eachRelatedType() or App.Photo.eachRelatedType().

似乎您没有自定义序列化程序.但是Ember-Data从不调用 eachRelatedType ,它仅对其进行定义.您使用的是哪个版本的Ember-Data?

It seems you don't have a custom serializer. But Ember-Data never calls eachRelatedType, it only defines it. What version of Ember-Data are you using?

似乎此特定问题是通过从Ember-Data 0.14升级而解决的.尽管没有确切原因,但尚不清楚.(可能是Ember-Data的错误.)

It seems that this particular issue was solved by upgrading from Ember-Data 0.14. Although no exact cause for it is known. (Could have been an Ember-Data bug.)

这篇关于Ember.js错误:“对象照片"没有方法&amp;#39; eachRelatedType&amp;#39;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆