イベントの起動
クライアント側のコントローラまたはヘルパー関数でイベントを起動します。force イベントは、Salesforce1 で処理されます。
このデモは、「取引先責任者の読み込み」で作成した取引先責任者コンポーネントを基に作成されています。
-
contactList サイドバーで、[CONTROLLER] をクリックして、contactListController.js という新しいリソースを作成します。プレースホルダコードを次のコードに置き換えて保存します。
1({ 2 gotoRecord : function(component, event, helper) { 3 // Fire the event to navigate to the contact record 4 var sObjectEvent = $A.get("e.force:navigateToSObject"); 5 sObjectEvent.setParams({ 6 "recordId": component.get("v.contact.Id"), 7 "slideDevName": 'related' 8 }) 9 sObjectEvent.fire(); 10 }, 11 12 editRecord : function(component, event, helper) { 13 // Fire the event to navigate to the edit contact page 14 var editRecordEvent = $A.get("e.force:editRecord"); 15 editRecordEvent.setParams({ 16 "recordId": component.get("v.contact.Id") 17 }); 18 editRecordEvent.fire(); 19 }, 20 21 relatedList : function (component, event, helper) { 22 // Navigate to the related cases 23 var relatedListEvent = $A.get("e.force:navigateToRelatedList"); 24 relatedListEvent.setParams({ 25 "relatedListId": "Cases", 26 "parentRecordId": component.get("v.contact.Id") 27 }); 28 relatedListEvent.fire(); 29 } 30}) -
Salesforce1 モバイルブラウザアプリケーションを更新し、次の要素をクリックしてイベントをテストします。
- 取引先責任者: force:navigateToSObject が起動され、取引先責任者レコードページでビューが更新されます。取引先責任者名は、次のコンポーネントに対応します。
1<div onclick="{!c.gotoRecord}"> 2 <force:recordView recordId="{!v.contact.Id}" type="MINI"/> 3</div> - [取引先責任者の編集] ボタン: force:editRecord が起動され、レコードの編集ページが開きます。[取引先責任者の編集] アイコンは、次のコンポーネントに対応します。
1<ui:button label="Edit" press="{!c.editRecord}"/>
- 取引先責任者: force:navigateToSObject が起動され、取引先責任者レコードページでビューが更新されます。取引先責任者名は、次のコンポーネントに対応します。
-
contactsController.js を開きます。doInit コントローラの後に次のコードを入力して保存します。
1createRecord : function (component, event, helper) { 2 // Open the create record page 3 var createRecordEvent = $A.get("e.force:createRecord"); 4 createRecordEvent.setParams({ 5 "entityApiName": "Contact" 6 }); 7 createRecordEvent.fire(); 8}, 9 10select : function(component, event, helper){ 11 // Get the selected value of the ui:inputSelect component 12 var selectCmp = component.find("selection"); 13 var selectVal = selectCmp.get("v.value"); 14 15 // Display all primary contacts or all contacts 16 if (selectVal==="All Primary"){ 17 var action = component.get("c.getPrimary"); 18 action.setCallback(this, function(response){ 19 var state = response.getState(); 20 if (component.isValid() && state === "SUCCESS") { 21 component.set("v.contacts", response.getReturnValue()); 22 } 23 }); 24 $A.enqueueAction(action); 25 } 26 else { 27 // Return all contacts 28 helper.getContacts(component); 29 } 30}
ページをプルダウンして離すと、ページのビューのすべてのデータが更新されます。これで、「Salesforce1 および Lightning Experience のコンポーネントの作成」で強調表示された領域をクリックして、コンポーネントをテストできます。
Salesforce1 とは関係なく使用できるスタンドアロンアプリケーションの作成例については、「スタンドアロン Lightning アプリケーションを作成する」 を参照してください。