ember-api-actions collectionAction 引发错误无法读取未定义的 属性 'constructor'

ember-api-actions collectionAction raise error Cannot read property 'constructor' of undefined

我有带有 collectionAction 的模型邮箱

import DS from 'ember-data'
import { collectionAction } from 'ember-api-actions'

export default DS.Model.extend({
  mailbox: DS.attr(), //display only
  pin: DS.attr(),
  download: collectionAction({ path: 'greeting'})
})

当我尝试从我的组件调用下载时出现错误

import Component from '@ember/component'
import Ember from 'ember'
import FileSaverMixin from 'ember-cli-file-saver/mixins/file-saver'

export default Component.extend(FileSaverMixin, {
  hifi: Ember.inject.service(),
  notifications: Ember.inject.service('notification-messages'),
  startPlay: true,
  changeset: {},
  actions: {
    toggle () {
      let hifi = this.get('hifi')
      if (this.get('startPlay')){
        this.set('startPlay', false )
        this.get('changeset').get('download')().then((content) => {
          this.saveFileAs(this.get('filename'), content, this.get('contentType'))
          })
        this.get('play')()
      } else {
        hifi.togglePause();
      }
    },
  }
})

错误是Uncaught TypeError: Cannot read 属性 'constructor' of undefined。 我检查我的鳕鱼/它和 ember-api-actions 一样 但是我的鳕鱼没有用。请帮我。我不明白哪里出了问题。

根据我从您的 post 中得知的信息,似乎 .get('download')() 不是调用 collectionAction 的正确方法。这可能是您的全部或部分问题。您应该可以使用以下方法来做到这一点:

this.get('change').download().then(() => {});

使用 ember-changeset 插件时遇到了麻烦。当我将模型而不是变更集模型放入我的组件时,一切正常。谢谢 Paul 为帮助我所做的努力。问题已解决。