G
G
GaserV2016-12-16 18:47:22
Ember.js
GaserV, 2016-12-16 18:47:22

How to parse data from JSON and output it?

Mastering Ember. A simple task. How to parse data and output it? I am currently getting an error:

The Broccoli Plugin: [TemplateCompiler] failed with:

Error: Parse error on line 16:
...ody>	          	{{ #each users as |use
r

Adapter(users.js):
import DS from 'ember-data';

export default DS.JSONAPIAdapter.extend({
  urlForFindAll(id, modelName, snapshot) {
      return 'users.json';
    }
});

Routes(main.js):
import Ember from 'ember';

export default Ember.Route.extend({
  users(){
    return this.store.findAll('user')
  }
});

Model(user.js):
import DS from 'ember-data';

export default DS.Model.extend({
  id: DS.attr('string')
});

Well, the template (main.hbs):
{{ #each users as |user| }}
              <tr>
                <td>{{ user.id }}</td>
                <td>Lorem</td>
                <td>ipsum</td>
                <td>dolor</td>
                <td>sit</td>
              </tr>
              {{ /each }}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Romanov, 2016-12-16
@Kaer_Morchen

import Ember from 'ember';

export default Ember.Route.extend({
  model(){
    return this.store.findAll('user')
  }
});

import DS from 'ember-data';

export default DS.Model.extend({
  // id указывать не нужно
});

{{#each model as |user|}}
              <tr>
                <td>{{ user.id }}</td>
                <td>Lorem</td>
                <td>ipsum</td>
                <td>dolor</td>
                <td>sit</td>
              </tr>
              {{ /each }}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question