【问题标题】:How to make HTML display a default string that is later replaced by a string taken from angular brackets?如何使 HTML 显示一个默认字符串,该字符串稍后会被尖括号中的字符串替换?
【发布时间】:2023-03-13 23:39:01
【问题描述】:

所以目前在车把文件中有这样的内容:

<p>Colour Selected: {{selectedType.colour}}</p>

...其中 selectedType 是 .js 文件中的一个对象,类似于:

selectedType: [{clothing: 'shirt', size: 'big', colour: 'blue'}, {clothing: 'socks', size: 'small', colour: 'red'}],

这是 ember-power-select 框的所有部分,例如,当您选择 shirt 时,该框允许网站立即在下方显示 Colour Selected: blue

这一切都很好,但是当尚未选择任何内容时,网页仅显示 Colour Selected: 没有给出任何内容。我想更改它,以便在默认情况下显示 blue,直到选择了某些内容。

【问题讨论】:

    标签: javascript html object ember.js drop-down-menu


    【解决方案1】:

    在控制器中,您可以检查 selectedType.colour 是否未定义或为空。如果未定义或为空,则为其分配默认值。

    【讨论】:

      【解决方案2】:

      你可以像下面这样写内联检查,

      {{if selectedType.colour selectedType.colour selectedType.firstObject.colour}}
      

      【讨论】:

        猜你喜欢
        • 2013-08-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-09
        • 1970-01-01
        • 2015-04-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多