While trying to build an Ember.js sample application, to call a REST Api and display results. I was able to call, fetch and display the results. In the component I am reading through the json response results.
How can I map the response data
to a pre-defined model and use that in the component instead? I could not find relevant docs at https://guides.emberjs.com/release/models/defining-models/ or https://guides.emberjs.com/release/in-depth-topics/making-api-requests/#toc_where-to-make-api-requests
Code details:
- Using this sample API https://reqres.in/api/users
- Route:
export default class UsersRoute extends Route {
async model() {
let response = await fetch('https://reqres.in/api/users');
let data = await response.json();
return data.data;
}
}
- Template:
<UserList
@title="List of Users"
@users=
/>
- Component:
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
Aucun commentaire:
Enregistrer un commentaire