2016-03-21 32 views
1

我正在嘗試安裝Mirage並嘗試僞造服務器的應用程序應用程序。我正在使用RestAdapter,該模型沒有從響應中獲取數據。無法映射商店對模型的響應 - EmberJS

適配器/的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: '[email protected]', 
     contactnumber: '+91 12345', 
     isFavourite: true, 
     isIncomplete: false, 
     isActive: true, 
     hasAccess: true 
    }, { 
     contactname: 'Sriram Swaminathan', 
     groupid: '12345', 
     email: '[email protected]', 
     contactnumber: '+91 12345', 
     isFavourite: true, 
     isIncomplete: false, 
     isActive: true, 
     hasAccess: true 
    }, { 
     contactname: 'Bhuvaneswari Swaminathan', 
     groupid: '12345', 
     email: '[email protected]', 
     contactnumber: '+91 12345', 
     isFavourite: false, 
     isIncomplete: false, 
     isActive: true, 
     hasAccess: true 
    } 
]; 

場景/ default.js

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

Config.js(幻影)

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> 

我不知道我出錯的地方。

請指導。提前致謝!!

+0

你能看到任何請求被解僱,並在開發人員工具中的網絡選項卡中的任何響應?另外,您是否使用Ember檢查器,並且可以看到模型中填充了數據? – Ms01

回答

0

在all.js(route)中,您可以嘗試使用return this.store.findAll('contact');和模型文件的名稱,而不是contacts.js說contact.js

+0

好的,讓我試試看。使用Inflector工作會使'聯繫人'變得不可數嗎? –