When converting my code from php to js, I can't get this bit to work:
searchEntity.translations[0].translation ?? searchEntity.name ?? searchEntity.name_en
I tried using two ||
searchEntity.translations[0].translation || searchEntity.name || searchEntity.name_en
but vue compiler only sees the first one and does't display whole component when second should be rendered, hovever if I display just second everything works:
searchEntity.name || searchEntity.name_en
however entity is polymorphic and it can be either of those 3.
I don't want to use v-if, it will need a repetitive code
(code is in the template, not computed)
EDIT
checking if translations exists in computed function solves issue
translatedName: function () {
if(this.searchEntity.translations) {
return this.searchEntity.translations[0].translation
} else {
return this.searchEntity.name || this.searchEntity.name_en || this.searchEntity.translation_fallback;
}
}