mardi 1 septembre 2015

Ember 2.0 component request for data

I am trying to create an organisations-table component, which will display a list of organisations, and the user for which each organisation belongs. I pass the model for the organisations into the component via an organisations.hbs template, which results in the following response from the server:

{    
  "organisations": [
    {
      "id": 0,
      "name": "Org0",
      "user": 1
    },
    {
      "id": 1,
      "name": "Org1",
      "user": 2
    },
    {
      "id": 2,
      "name": "Org2",
      "user": 2
    }
  ]
}

In order to display the username for each user, the component then makes its own call to the server querying against the id for each of the users.

Is this the correct approach? My understanding is that components are supposed to be isolated by design, only aware of the data passed into them, but in this example, the component is sending its own requests to the server for the additional data.

I have created this ember twiddle to hopefully give an idea of the structure of the app (comments welcome!).

Thanks in advance




Aucun commentaire:

Enregistrer un commentaire