简体   繁体   English

灰烬-destroyRecord不是模型对象上的函数

[英]Ember - destroyRecord is not a function on model object

I have an action that passes a model object to the route to have it deleted. 我有一个将模型对象传递到路线以将其删除的操作。 But when I call delete on that object, I get model.destroyRecord is not a function. 但是,当我对该对象调用delete时,我得到了model.destroyRecord不是一个函数。

  model() {
    return this.store.findRecord('user', 980190980).then((user) => {
      return user.getPlaylists();
    }.bind(this));
  },

  <i class="fa-icon fa fa-trash" aria-hidden="true" {{action "deletePlaylist" playlist}} style="margin-top:10px"></i>

  deletePlaylist(playlist) {
    this.get('playlists').removeObject(playlist);
    playlist.destroyRecord();
  }

If I do: 如果我做:

this.store.findRecord('playlist', playlist.id).then(playlist => playlist.destroyRecord());

I get the following error: 我收到以下错误:

Attempted to handle event 'pushedData' while in state root.deleted.inFlight

I would put a debugger; 我会放一个debugger; statement before your call destroyRecord() and check to see that the object type is an Ember Data model. 在调用destroyRecord()之前的语句,并检查对象类型是否为Ember Data模型。 I suspect that .getPlaylists() is not an DS.Model type and its a plain javascript object (POJO). 我怀疑.getPlaylists()不是DS.Model类型,它不是纯JavaScript对象(PO​​JO)。

Your error root.deleted.inFlight indicates that theres an error saving your record and you cannot delete it if it cannot first be saved. 您的错误root.deleted.inFlight表示保存记录时出错,如果无法首先保存,则无法删除。 Ember is trying to let you know its a dirty model, meaning it has changes and it has not been saved. Ember试图让您知道它的脏模型,这意味着它已更改且尚未保存。 http://emberjs.com/api/data/classes/DS.RootState.html http://emberjs.com/api/data/classes/DS.RootState.html

deleteRecord() will delete it from the store without calling the server and destroyRecord() will do the same as deleteRecord() and call the server to notify this record should be deleted from any persistent storage. deleteRecord()将在不调用服务器的情况下将其从存储中删除, destroyRecord()将与deleteRecord()相同,并调用服务器以通知该记录应从任何持久性存储中删除。

Also there are some issues with your code. 您的代码也有一些问题。 The .bind() is not valid. .bind()无效。 The findRecord promise doesnt have proper error handling: http://emberjs.com/api/classes/RSVP.Promise.html findRecord承诺没有适当的错误处理: http : findRecord

promise.then(function(value) {
  // on fulfillment
}, function(reason) {
  // on rejection
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM