Let’s say I have the following data:
[
{
"type": "video",
"url": "http://videos.com/2346",
"title": "Awesome video!",
"description": "An awesome video",
"embed_url": "http://videos.com/v/2346.mp4"
},
{
"type": "photo",
"url": "http://photos.com/2346",
"title": "Awesome photo!",
"description": "An awesome photo",
"embed_url": "http://photo.com/p/2346.jpeg"
}
]
And I want to display it in the following template:
{{#each item in model}}
<h1>{{item.title}}</h1>
{{embedded-object item=item}}
{{/each}}
How can I setup the embedded-object
component such that it will display a <video>
element if the type
property is video
, and an <img>
element if the type
is photo
?
One idea I had was to create computed properties on the component:
Ember.Component.extend({
isVideo: function() {
return this.get('type') == 'video';
}.property('type'),
isPhoto: function() {
return this.get('type') == 'photo';
}.property('type'),
isRich: function() {
return this.get('type') == 'rich';
}.property('type'),
isLink: function() {
return this.get('type') == 'link';
}.property('type'),
});
And then in the embedded-object
component:
{{#if isVideo}}
{{embed-video item=item}}
{{/if}}
{{#if isPhoto}}
{{embed-photo item=item}}
{{/if}}
{{#if isRich}}
{{embed-rich item=item}}
{{/if}}
{{#if isLink}}
{{embed-link item=item}}
{{/if}}
But this doesn’t feel like it’s the correct thing to do. Any ideas?