Search code examples
javascriptember.jsember-dataember-cliember-controllers

Ember cli replace image standard if image model is null in json


I want to display a standard image if the model in my json is null.

This is my function where first i successfully achieve to format the url in order to make it bigger (eg: https://i1.sndcdn.com/artworks-000121961221-bzjnxn-large.jpg to https://i1.sndcdn.com/artworks-000121961221-bzjnxn-t500x500.jpg) but then i can not assign a standard image when the model (artwork_url) is null.

formattedArtwork: Ember.computed('artwork_url', function() {
    var splitURL, url;
    if (this.get('artwork_url')) {
        url = this.get('artwork_url');
        splitURL = url.split('-large');
        return splitURL[0] + '-t500x500' + splitURL[1];
    } else {
        url = this.get('https://mystandardimage.jpg');
        return url;
    }
}),

So if it gets the arwork_url i can format and display the img but if it does not get i would like to put a general image url i created, at the moment it says that my url is undefined although that url (https://i1.sndcdn.com/artworks-000121961221-bzjnxn-t500x500.jpg) really exists.

What am i doing wrong?

See the printscreen

enter image description here


Solution

  • After the debugger line, you should just return "https://i1.sndcdn.com/artworks-000121961221-bzjnxn-t500x500.jpg"