条件式
3 項演算子と <aura:if> タグを使用した条件式の例を示します。
3 項演算子
次の式は、3 項演算子を使用して、2 つの値のいずれかを条件に応じて出力します。
1swfobject.registerObject("clippy.codeblock-0", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17<a class="{!v.location == '/active' ? 'selected' : ''}" href="#/active">Active</a>{!v.location == '/active' ? 'selected' : ''} 式は、location 属性が /active に設定されているかどうかを確認して、HTML <a> タグの class 属性を条件に応じて設定します。true の場合は、式が class を selected に設定します。
条件付きマークアップでの <aura:if> の使用
マークアップの次のスニペットは、<aura:if> タグを使用して��編集ボタンを条件に応じて表示します。
1swfobject.registerObject("clippy.codeblock-1", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17<aura:attribute name="edit" type="Boolean" default="true">
18<aura:if isTrue="{!v.edit}">
19 <ui:button label="Edit"/>
20 <aura:set attribute="else">
21 You can’t edit this.
22 </aura:set>
23</aura:if>edit 属性が true に設定されている場合は、ui:button が表示されます。それ以外の場合は、else 属性のテキストが表示されます。