Di aplikasi saya, saya memiliki tampilan XML yang terdiri dari smartform. Saya memiliki kebutuhan untuk mengakses elemen input (melalui sap.ui.getCore().byId()
) yang tersedia setelah smartform diurai dan dirender.
onAfterRendering
di pengontrol untuk tampilan saya terpicu segera setelah tampilan dirender (saya mendapatkan semua elemen non-smartform seperti judul, dll.), tetapi sebelum smartform diurai dan dirender. Tes dasar melalui alert
juga membuktikan hal ini secara visual.
Apakah ada peristiwa yang dipicu setelah smartform dirender yang dapat saya sambungkan untuk mengakses elemen input saya?
Panduan pengembang panduan memperluas smartform dan dengan demikian memiliki init
metode, tetapi dalam kasus saya, saya memperluas basecontroller dan init saya untuk tampilan halaman.
Terima kasih atas petunjuknya.
Pandangan ku:
<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....
}
});
});