![](/img/trans.png)
[英]Ember destroyRecord (or deleteRecord then save) using ember-cli-mirage failing
[英]Ember - destroyRecord is not a function on model object
我有一個將模型對象傳遞到路線以將其刪除的操作。 但是,當我對該對象調用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();
}
如果我做:
this.store.findRecord('playlist', playlist.id).then(playlist => playlist.destroyRecord());
我收到以下錯誤:
Attempted to handle event 'pushedData' while in state root.deleted.inFlight
我會放一個debugger;
在調用destroyRecord()
之前的語句,並檢查對象類型是否為Ember Data
模型。 我懷疑.getPlaylists()
不是DS.Model
類型,它不是純JavaScript對象(POJO)。
您的錯誤root.deleted.inFlight
表示保存記錄時出錯,如果無法首先保存,則無法刪除。 Ember試圖讓您知道它的臟模型,這意味着它已更改且尚未保存。 http://emberjs.com/api/data/classes/DS.RootState.html
deleteRecord()
將在不調用服務器的情況下將其從存儲中刪除, destroyRecord()
將與deleteRecord()
相同,並調用服務器以通知該記錄應從任何持久性存儲中刪除。
您的代碼也有一些問題。 .bind()
無效。 findRecord
承諾沒有適當的錯誤處理: http : findRecord
promise.then(function(value) {
// on fulfillment
}, function(reason) {
// on rejection
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.