0
votes

I'm using the ember-data last version with an important problem I 'm trying to solve.

The find function by id works perfect and the proper record is loaded into the Data Store so I can obtain the attributes that I want in the template for render them.

App.PostRoute = Ember.Route.extend({
  model: function(params) {
    return this.store.find('post', params.post_id);
  }
});

On the other side, the findAll function doesn't work for me and the problem is Ember doesn't throw any error. In addition, Ember doesn't load any record and besides that I don't know how to iterate over the RecordArray returned in the template.

App.PostsRoute = Ember.Route.extend({
  model: function() {
    return this.store.find('post');
  }
});

Any suggestions? Thanks for the help.

2
What's your json response from your endpoint?Kingpin2k
My JSON response for one post is {"id":"1","attribute1":"value1", ...,"attributen": "valuen"} while my JSON response for all posts is [{"id":"1","attribute1":"value1", ...,"attributen": "valuen"},{"id":"2","attribute1":"value1", ...,"attributen": "valuen"}]. I'm aware of my no ember standard response so I'm using RESTSerializer.akruspe
You'll need to give us the serializer in order to debug. Additionally you can iterate over the response: this.store.find('post').then(function(arr){ console.log(arr.get('length'));});Kingpin2k
My RESTSerializer is exactly like the TRANSITION.md one with 'serializerIntoHash, extractSingle` and extractArray functions but finally I gonna forget this serializer system and I gonna use a JSON response according to Ember so it works now. Thanks!akruspe

2 Answers

1
votes

From your comment above, if your response looks like:

[
    {"id":"1","attribute1":"value1", ...,"attributen": "valuen"},
    {"id":"2","attribute1":"value1", ...,"attributen": "valuen"}
]

and you have not provided a custom serializer that modifies your response in extractArray(...), then data will not get processed because Ember Data expects something like:

{
    "pluralizedModelName": [
        {"id":"1","attribute1":"value1", ...,"attributen": "valuen"},
        {"id":"2","attribute1":"value1", ...,"attributen": "valuen"}
    ]
}

See the Ember Data 1.0 specific code: https://github.com/emberjs/data/blob/master/TRANSITION.md#rest-adapter-and-serializer-configuration

0
votes

How are you referencing the model in the template? Are you using the generated controller, or defining it yourself?

Also, the RecordArray should be automatically resolved by your Handlebars template. Try referencing {{#each}}. By default, your template will look for the property on the controller and if not found, bubble up to the model. If you can, create a JSBin (emberjs.jsbin.com) and we can collaborate with an example.

Edit: Also, are you using Fixture or Rest Adapter?