ในแอปของฉัน ฉันมีมุมมอง XML ที่ประกอบด้วย smartform ฉันจำเป็นต้องเข้าถึงองค์ประกอบอินพุต (ผ่าน sap.ui.getCore().byId()
) ที่พร้อมใช้งานหลังจากแยกวิเคราะห์และเรนเดอร์สมาร์ทฟอร์มแล้ว
onAfterRendering
ในคอนโทรลเลอร์สำหรับมุมมองของฉันจะทริกเกอร์ทันทีที่มุมมองถูกเรนเดอร์ (ฉันได้รับองค์ประกอบที่ไม่ใช่สมาร์ทฟอร์มทั้งหมด เช่น ชื่อ ฯลฯ) แต่ก่อนที่สมาร์ทฟอร์มจะถูกแยกวิเคราะห์และเรนเดอร์ การทดสอบเบื้องต้นผ่าน alert
ก็พิสูจน์สิ่งนี้ด้วยสายตาเช่นกัน
มีเหตุการณ์ใดบ้างที่เกิดขึ้นเมื่อสมาร์ทฟอร์มแสดงผลแล้ว ซึ่งฉันสามารถเชื่อมต่อเพื่อเข้าถึงองค์ประกอบอินพุตของฉันได้
คู่มือนักพัฒนา คำแนะนำแบบทีละขั้นตอนกำลังขยาย Smartform และจึงมี init
แต่ในกรณีของฉัน ฉันกำลังขยาย basecontroller และ init ของฉันมีไว้สำหรับการดูหน้าเว็บ
ขอบคุณสำหรับคำแนะนำใด ๆ
มุมมองของฉัน:
<mvc:View
controllerName="myns.controller.Add"
xmlns:mvc="sap.ui.core.mvc"
xmlns:semantic="sap.m.semantic"
xmlns:smartfield="sap.ui.comp.smartfield"
xmlns:smartform="sap.ui.comp.smartform"
xmlns="sap.m">
<semantic:FullscreenPage
id="page"
title="{i18n>addPageTitle}"
showNavButton="true"
navButtonPress="onNavBack">
<semantic:content>
<smartform:SmartForm
id="form"
editable="true"
title="{i18n>formTitle}"
class="sapUiResponsiveMargin" >
<smartform:Group
id="formGroup"
label="{i18n>formGroupLabel}">
<smartform:GroupElement>
<smartfield:SmartField
id="nameField"
value="{Name}" />
</smartform:GroupElement>
</smartform:Group>
</smartform:SmartForm>
</semantic:content>
<semantic:saveAction>
<semantic:SaveAction id="save" press="onSave"/>
</semantic:saveAction>
<semantic:cancelAction>
<semantic:CancelAction id="cancel" press="onCancel"/>
</semantic:cancelAction>
</semantic:FullscreenPage>
My Controller:
sap.ui.define([
"myns/controller/BaseController",
"sap/ui/core/routing/History",
"sap/m/MessageToast"
],function(BaseController, History, MessageToast){
"use strict";
return BaseController.extend("myns.controller.Add",{
onInit: function(){
this.getRouter().getRoute("add").attachPatternMatched(this._onRouteMatched, this);
},
onAfterRendering: function(){
//I tried my sap.ui.getCore().byId() here but does not work
//An alert shows me this triggers before the smartform is rendered but
//after all the other non-smartform elements have rendered
},
_onRouteMatched: function(){
// register for metadata loaded events
var oModel = this.getModel();
oModel.metadataLoaded().then(this._onMetadataLoaded.bind(this));
},
_onMetadataLoaded:function(){
//code here....
},
onNavBack: function(){
//code here....
}
});
});