无法映射商店对模型的响应 - EmberJS

时间:2016-03-21 09:12:04

标签: javascript ember.js ember-cli-mirage

我正在尝试一个ember应用程序,我已经安装了Mirage并试图伪造服务器。我使用的是RestAdapter,模型没有从响应中获取数据。

适配器/ application.js中

import DS from 'ember-data';

export default DS.RESTAdapter.extend({
});

contacts.js(型号)

import DS from 'ember-data';
import ContactModel from 'c360-app/models/contactsmodel';
export default ContactModel.extend({
    contactname: DS.attr(''),
    groupid: DS.attr(''),
    email: DS.attr(''),
    contactnumber: DS.attr('')
});

all.js(路线)

import ContactRoute from 'c360-app/routes/contactsroute';
export default ContactRoute.extend({
    model: function() {
        return this.store.findAll('contacts');
    }
});

夹具/ contacts.js

export default [  
    {
        contactname: 'Anusha Swaminathan',
        groupid: '12345',
        email: 'xyz@gmail.com',
        contactnumber: '+91 12345',
        isFavourite: true,
        isIncomplete: false,
        isActive: true,
        hasAccess: true
    }, {
        contactname: 'Sriram Swaminathan',
        groupid: '12345',
        email: 'xyz@gmail.com',
        contactnumber: '+91 12345',
        isFavourite: true,
        isIncomplete: false,
        isActive: true,
        hasAccess: true
    }, {
        contactname: 'Bhuvaneswari Swaminathan',
        groupid: '12345',
        email: 'xyz@gmail.com',
        contactnumber: '+91 12345',
        isFavourite: false,
        isIncomplete: false,
        isActive: true,
        hasAccess: true
    }
];

场景/ default.js

export default function( server ) {
   server.loadFixtures();
}

Config.js(Mirage)

export default function() {
  this.get('/contacts', function(db){
    return {contacts: db.contacts};
  });
}

与-listing.hbs

    <table class = "contacts-table-header">
        <tr>
            <th>Contact Name</th>
            <th>Group ID </th>
            <th>Email Address</th>
            <th>Contact Number</th> 
        </tr>
{{#each model as |contact|}}
        <tr>
            <td>{{contact.contactname}}</td>
            <td>{{contact.groupid}}</td>
            <td>{{contact.email}}</td>
            <td>{{contact.contactnumber}}</td>
        </tr>

{{/each}}
</table>

我不知道我哪里出错了。

请指导。在此先感谢!!

1 个答案:

答案 0 :(得分:0)

在all.js(route)中你可以尝试使用return this.store.findAll(&#39; contact&#39;);和模型文件名而不是contacts.js说contact.js