[英]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.