親属性による表示ラベル値の設定
親属性による表示ラベル値の設定は、子コンポーネントの表示ラベルを制御する場合に便利です。
コンテナコンポーネントに inner.cmp という別のコンポーネントが含まれているとします。コンテナコンポーネントの属性で inner.cmp の表示ラベル値を設定します。これを行うには、属性型とデフォルト値を指定します。内部コンポーネントの表示ラベルを設定する場合、次の例のように親属性でデフォルト値を設定する必要があります。
次のコンポーネントは、_label 属性のデフォルト値 My Label を含むコンテナコンポーネントです。
1swfobject.registerObject("clippy.codeblock-0", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17<aura:component>
18 <aura:attribute name="_label"
19 type="String"
20 default="My Label"/>
21 <ui:button label="Set Label" aura:id="button1" press="{!c.setLabel}"/>
22 <auradocs:inner aura:id="inner" label="{!v._label}"/>
23</aura:component>次の inner コンポーネントには、テキストエリアコンポーネントおよびコンテナコンポーネントで設定された label 属性が含まれます。
1swfobject.registerObject("clippy.codeblock-1", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17<aura:component>
18 <aura:attribute name="label" type="String"/>
19 <ui:inputTextarea aura:id="textarea"
20 label="{!v.label}"/>
21</aura:component>次のクライアント側のコントローラアクションで表示ラベル値を更新します。
1swfobject.registerObject("clippy.codeblock-2", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17({
18 setLabel:function(cmp) {
19 cmp.set("v._label", 'new label');
20 }
21})コンポーネントが初期化されると、My Label という表示ラベルのボタンおよびテキストエリアが表示されます。コンテナコンポーネントのボタンがクリックされると、setLabel アクションによって、inner コンポーネントの表示ラベル値が更新されます。このアクションによって label 属性が検索され、その値が new label に設定されます。