1

EmberJs noob here. I am trying to do something pretty simple: display a list of albums represented by an image. When the user clicks the image, the album's photos are displayed underneath. Right now, I am able to loop through each album and display each album image. From there I am able to click the link which is an Ember action link and display the number of photos in the album. I have created a JS Bin item to demonstrate this:

As a noob, I tried to pass into the link click event handler the album's photos thinking that I could assign that array to the AlbumController's albumPhotos property then loop through my photos but that does not seem to be working.

Any ideas on what I am doing wrong? Also, any suggestions on best practices on how to organize this code would also be much appreciated. Thanks

gyochum
  • 131
  • 4
  • 12

1 Answers1

2

Your approach is correct, but there are some issues with your fixture data.

  • your fixture javascript is not formatted property (you need to remove the -)
  • you need to not embed the Photos records, instead put them in the Photos fixture and reference them by id
  • need to add some ids to your fixture records and make sure some are not duplicated

Working JSBin

CraigTeegarden
  • 8,173
  • 8
  • 38
  • 43
  • thank you c4p, that works great. I am curious, however, with what to do when I switch to the RESTAdapter. Similar to loading with Fixture data, would my Photos property need to be modified to use an array of photo Ids? Then use those Ids to make service calls to get each individual photo? – gyochum Jul 08 '13 at 18:26
  • The RESTAdapter has a way to configure records to be "embedded". There isn't super good documentation but you can find some info in a few places, here are a few: http://discuss.emberjs.com/t/embedded-records-in-ember-data/1631 http://stackoverflow.com/questions/14591892/how-to-access-nested-object-in-json-with-ember-data – CraigTeegarden Jul 08 '13 at 18:37