Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4829

Parsing a json object in a route

$
0
0

@emanuk wrote:

ember-cli: 2.13.2 node: 7.8.0

Hello, I'm a newbie at ember and I want to do something that looks super simple, but I can't find the right way.

I have this code in ./routes/tutoriel-01.js

import Ember from 'ember';
import DS from 'ember-data';
import config from '../config/environment';
const {Logger}= Ember;

export default Ember.Route.extend({
  model: function() {
    return Ember.$.getJSON(config.APP.drupal_tutoriel);
  }
});

And the following in ./templates/tutoriel-01.hbs

 <ul>
  {{#each model as |elem|}}
    <li>{{elem.node_title}}</li>
  {{/each}}
</ul>

The problem is that $.getJSON return 8 objects and I just want one. So the template will print all the node_title of the 8 objects.

[
  {
    "node_title": "Événements",
    "nid": "1234",
    "numero_tutoriel": "1",
    "field_image_tutoriel": "http://example.org/sites/files/evenements_tuto_mobile.png",
    "body": "<p>some text</p>\n"
  },
  {
    "node_title": "À lire",
    "nid": "45678",
    "numero_tutoriel": "2",
    "field_image_tutoriel": "http://example.org/sites/files/tuto_mobile.png",
    "body": "<p>more text.</p>\n"
  },
(...)
]

I though that I could use in my route something like:

return Ember.$.getJSON(config.APP.drupal_tutoriel)[0]
return Ember.$.getJSON(config.APP.drupal_tutoriel).[0]

or

in my template:

{{#each model.[0] as |elem|}}

but it's not working.

Once I have working code, I'll try it with a promise.

I read about Ember Data, but I can figure out how to use it this particular case.

TIA

-Emmanuel

Posts: 4

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 4829

Trending Articles