Ember-CLI with Mirage gives me this error : Uncaught TypeError: Cannot read property 'destroyRecord' of undefined

Ember-CLI with Mirage gives me this error : Uncaught TypeError: Cannot read property 'destroyRecord' of undefined

我正在尝试使用 Mirage 模拟服务器创建一个简单的 Ember-CLI 应用程序。我可以在数据库中插入和生成随机数据,但我不能删除记录。

我的application.hbs

<h2 id="title">Contacts</h2>

{{#each contact in model}}
<table>
<tr>    
  <td>{{contact.name}}</td>
  <td>{{contact.surname}}</td>
  <td>{{contact.age}}</td>
  <td><button {{action 'deleteContact'}}>X</button></td>  //button to delete the contact
</tr>
</table>
{{/each}}

<br>
<p>New contact</p>
{{input value=newName}}
<button {{action 'createContact' newName}}>Create contact</button>

然后在 application.js 中定义操作

import Ember from 'ember';

export default Ember.Route.extend({
    model() 
    {
        return this.store.findAll('contact');
    },

    actions: 
    {
        createContact(newName)
        {
            this.store.createRecord('contact',
            {
                name: newName
            }).save();
        },

        deleteContact(contact) 
        {   
            return contact.destroyRecord(); // if I comment this line the error doesn't show
        }
    }
});

当我点击按钮时,我在 Ember 检查器中得到这个错误: 未捕获的类型错误:无法读取未定义删除联系人的 属性 'destroyRecord' @ application.js:18triggerEvent

您必须将 contact 记录实例传递给带有签名 deleteContact (contact) 的操作 deleteContact

<button {{action 'deleteContact' contact}}>X</button></td>