[英]SAPUI5 Form Add Label and Input dynamically and set ID for Input but not function
我正在創建一個應用程序,使用戶能夠動態添加新標簽並輸入到表單中。 但是我已經設置了新的輸入ID並啟用了false,由用戶動態添加。 但是當我單擊編輯按鈕時,啟用設置為true。 這是行不通的。 我的應用程序無法讀取我在表單中動態添加的輸入ID。
以下是我的示例代碼。
添加新標簽並輸入到我當前的表單中
var _oSF2 = this.getView().byId("Extension_Form");
_oSF2.addContent(new sap.m.Label({
text: "Classification"
}));
_oSF2.addContent(new sap.m.Input({
id : "idExtensionInput1",
text : "text",
enabled: false
}));
將新輸入的啟用設置為true
handleEditPress: function () {
this.getView().byId("idExtensionInput1").setEnabled(true);
}
您已將輸入添加到無視圖。 在您的情況下,您只能使用sap.ui.getCore().byId("idExtensionInput1")
訪問輸入,但是正確的方法是使用this.getView().createId()
並將其添加到正確的視圖中。
var _oSF2 = this.getView().byId("Extension_Form");
_oSF2.addContent(new sap.m.Label({
text: "Classification"
}));
<!-- language: lang-js -->
_oSF2.addContent(new sap.m.Input({
id : this.getView().createId("idExtensionInput1"), //Use createId() for this.getView()
text : "text",
enabled: false
}));
handleEditPress: function () {
this.getView().byId("idExtensionInput1").setEnabled(true);
}
一個評論:new sap.m.Input的第一個參數是id。 請寫出:
_oSF2.addContent(new sap.m.Input(this.getView().createId("idExtensionInput1"), {
text : "text",
enabled: false
}));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.