jeudi 22 septembre 2016

How to deal with list of partial data in ember

(Ember 2, if it matters)

I am trying to show a list of search results on an ember page. The api I am using basically just returns a list of ids and names for a particular record type (let's call it foo). Unfortunately, I also need to get a thumbnail with each item and the search results route doesn't provide it. The search-result model is comprised of a list of several attributes, each of which is simply a DS.hasMany to a different model, e.g.

  foos: DS.hasMany('foo', {
    async: true
  }),
  bars: DS.hasMany('bar', {
    async: true
  }),

The data returned from the server looks like this:

{
    "actions": [{
        ... irrelevant
    }],
    "data": {
        "foos": [{
            "id": "test",
            "name": "test"
        }],
        "meta": {
            "total": 1
        }
    }
}

Foo's model has lots of properties, including name, thumbnailURI, etc.

When I try to use in my template, the property is undefined; I would have expected the store to fetch the model for foo/test, since it's missing the image property, but it doesn't. What am I supposed to do to tell Ember -- hey, that list of items from the server didn't get all of the properties you need; go ask the server for that data for each item via /api/foo/test, /api/foo/test2, etc.




Aucun commentaire:

Enregistrer un commentaire