Skip to content

Instantly share code, notes, and snippets.

@joachimhs
Created May 23, 2012 13:40
Show Gist options
  • Save joachimhs/2775283 to your computer and use it in GitHub Desktop.
Save joachimhs/2775283 to your computer and use it in GitHub Desktop.
No Properties from Ember Data
Problem: The JSON is received from the server, but only the "id" property have a value. The GUI only displays the String "2 1", an the {{photoName}} is ignored. Manually calling MyApp.PhotoController.get('content').objectAt(0).get('photoName') returns "undefined", whereas MyApp.PhotoController.get('content').objectAt(0).get('id') returns the correct ID.
Any Sugggestions ?
//My Model:
MyApp.Photo = DS.Model.extend({
id: DS.attr('number'),
photoName: DS.attr('string'),
photoDescription: DS.attr('string'),
photoFullSizeURL: DS.attr('string'),
photoThumbnailURL: DS.attr('string')
});
//We are reopening the class so that we can add the URL that the
//JSON Hash will be received from
MyApp.Photo.reopenClass({
url: 'photos.json'
});
//My StateManager
MyApp.stateManager = Ember.StateManager.create({
rootElement: '#mainArea',
initialState: 'showMainView',
showMainView: Ember.ViewState.create({
enter: function(stateManager) {
this._super(stateManager);
var photos = MyApp.store.findAll(MyApp.Photo);
MyApp.PhotosController.set('content', photos);
},
view: Em.ContainerView.create({
childViews: ['photoListView'],
photoListView: Em.View.extend({
elementId: 'photoList',
templateName: 'photo-list-view',
contentBinding: 'MyApp.PhotosController.content'
})
})
})
})
//My Controller:
MyApp.PhotosController = Ember.ArrayProxy.create({
content: []
});
//My template:
<script type="text/x-handlebars" data-template-name="photo-list-view">
PHOTOS:<br/>
{{#each content}}
{{photoName}} {{id}}
{{/each}}
</script>
//JSON Received from server:
[
{
"id": 2,
"photoName": "Bird Photo",
"photoDescription": "Bird Photo Description",
"photoFullSizeUrl": "photos/bird.jpg",
"photoThumbnailUrl": "photos/bird_thumb.png"
},
{
"id": 1,
"photoName": "Bird Photo 2",
"photoDescription": "Bird Photo Description 2",
"photoFullSizeUrl": "photos/bird.jpg",
"photoThumbnailUrl": "photos/bird_thumb.png"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment