dimanche 29 janvier 2017

Need help to understand how ember.js Ember Data works

I am very new to ember.js.

I have the following code which I need to change to retrieve data from the server using multiple models (using multiple JSON/RESTful calls).

This (single model version) WORKS:

In app/routes/index.js:

import Ember from 'ember';

export default Ember.Route.extend({
  model() {
    return this.get('store').queryRecord('wallet', {balance: true});
  }
});

and in wallet-balance.hbs:

<div>Your Total Score:  </div>

I changed to this and it WORKS:

import Ember from 'ember';
import RSVP from 'rsvp';

export default Ember.Route.extend({
  model() {
    return RSVP.hash({
      wallet: this.get('store').queryRecord('wallet', {balance: true})
    });
  }
});

and in wallet-balance.hbs:

<div>Your Total Score:  </div>

BUT if I change to the following ("wallet" -> "anythingelse"), it WON'T WORK:

import Ember from 'ember';
import RSVP from 'rsvp';

export default Ember.Route.extend({
  model() {
    return RSVP.hash({
      anythingelse: this.get('store').queryRecord('wallet', {balance: true})
    });
  }
});

and in wallet-balance.hbs:

<div>Your Total Score:  </div>

I'm trying to understand why. Where is it picking up from for the definintion "wallet" - and why changing to "anythingelse" won't work? Where else is the code for "wallet" referring to?




Aucun commentaire:

Enregistrer un commentaire