mercredi 5 juillet 2017

Ember - JSON import - not displaying template content

I am working with the Ember CLI.

I have a JSON in this format:

public/assets/data.json

{
  "important": [
    {
      "name": "first",
      "value": 10
    },
    {
      "name": "second",
      "value": 10
    },
    ...
  ],
  "unimportant1": {
    ...
  },
  "unimportant2": {
    ...
  }
  ...
}

I want to import "important" for use in a model. I have attempted the following:

app/routes/important.js

import Ember from 'ember';

export default Ember.Route.extend({
  model() {
    return Ember.$.getJSON("/assets/data.json").important;
  }
});

The console log does not display any errors.

I want to display the items in "important". I have attempted the following:

app/templates/important.hbs


  <div>
    
  </div>


However, nothing is displayed. How can I get them to display?

I noticed that the items display as expected if I copy and paste the array into the return statement:

app/routes/important.js

import Ember from 'ember';

export default Ember.Route.extend({
  model() {
    return [
      {
        "name": "first",
        "value": 10
      },
      {
        "name": "second",
        "value": 10
      },
      ...
    ];
  }
});

Any help is much appreciated.




Aucun commentaire:

Enregistrer un commentaire