samedi 15 juin 2019

How to pass data from different models to component in Ember?

I have a little question in Ember. There is several routes that receive data from several JSON files, and one component where the data is to be passed. Here is a JSON file named 'data':

[
  { "name": "Mike", "age": "15"},
  { "name": "John", "age": "25"},
  { "name": "Alex", "age": "30"}
]  

I have a route that get data from this JSON and retirns it:

import Route from '@ember/routing/route';
import fetch from 'fetch';

export default Route.extend({
  model() {
    var data = fetch('/data/fbbmd.json').then(function (response) {
      return response.json();
    }); 
    return data;
  }
});   

and the component hbs template:

<h5><i></i></h5>        

And we have another JSON and another route, and a third JSON and a third route and so on, and the one component averywhere. Maybe my construktion is wrong, and I should'nt use the model in route, or another, so tell me please, how to pass data from JSON to component template?




Aucun commentaire:

Enregistrer un commentaire