force:outputField
バインドされるデータに基づいて型固有の具体的な出力コンポーネントの実装を提供するコンポーネント。
Salesforce オブジェクトの項目値の参照のみ表示を表します。このコンポーネントは、関連項目およびその表示方法の属性を考慮します。たとえば、コンポーネントに日時値が含まれる場合、デフォルトの出力値にはユーザのロケールでの日時が含まれます。
Winter '18 以降は、代わりに lightning:outputField を使用することをお勧めします。
次の例では、取引先責任者名のデータを表示します。value 属性を使用して項目をバインドし、デフォルト値を指定してオブジェクトを初期化します。
1<aura:component controller="ContactController">
2 <aura:attribute name="contact" type="Contact"
3 default="{ 'sobjectType': 'Contact' }"/>
4 <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
5 <force:outputField value="{!v.contact.Name}"/>
6</aura:component>レコードデータを読み込むには、取引先責任者を返す Apex コントローラにコンテナコンポーネントを接続します。
1public with sharing class ContactController {
2 @AuraEnabled
3 public static Contact getContact() {
4 return [select Id, Name from Contact Limit 1];
5 }
6}クライアント側コントローラを介して取引先責任者データをコンポーネントに渡します。
1({
2 doInit : function(component, event, helper) {
3 var action = component.get("c.getContact");
4 action.setCallback(this, function(response) {
5 var state = response.getState();
6 if (state === "SUCCESS") {
7 component.set("v.contact", response.getReturnValue());
8 console.log(response.getReturnValue());
9 }
10 });
11 $A.enqueueAction(action);
12 }
13})このコンポーネントは、Lightning Design System スタイル設定を使用しません。Lightning Design System スタイル設定を継承する入力項目が必要な場合は、lightning:input を使用します。
属性
| 属性名 | 属性型 | 説明 | 必須項目 |
|---|---|---|---|
| body | Component[] | コンポーネントのボディ。マークアップでは、これはタグのボディに含まれるすべてを指します。 | |
| class | String | コンポーネントに添付される CSS スタイル。このスタイルは、コンポーネントで出力される基本スタイルに追加されます。 | |
| value | Object | バインドする Salesforce 項目のデータ値。 |