简体   繁体   English

SAPUI5表单动态添加标签和输入并为输入设置ID,但不起作用

[英]SAPUI5 Form Add Label and Input dynamically and set ID for Input but not function

I am creating an application enable user to dynamically add new label and input into form. 我正在创建一个应用程序,使用户能够动态添加新标签并输入到表单中。 But I have set the new input id and enabled is false dynamically added by user. 但是我已经设置了新的输入ID并启用了false,由用户动态添加。 But when I click edit button, enabled set to true. 但是当我单击编辑按钮时,启用设置为true。 It does not work. 这是行不通的。 My application cant read the input id that I added dynamically in form. 我的应用程序无法读取我在表单中动态添加的输入ID。

The following is my sample code. 以下是我的示例代码。

Add new label and input into my current form 添加新标签并输入到我当前的表单中

        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
            }));

Set enablement for new input to true 将新输入的启用设置为true

    handleEditPress: function () {
        this.getView().byId("idExtensionInput1").setEnabled(true);

    }

You've added the input to no view. 您已将输入添加到无视图。 In your case, you can only access the input with sap.ui.getCore().byId("idExtensionInput1") but the correct way is to use this.getView().createId() and add it to the right view. 在您的情况下,您只能使用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);
    }

One comment: The first parameter for new sap.m.Input is the id. 一个评论:new sap.m.Input的第一个参数是id。 Please write: 请写出:

       _oSF2.addContent(new sap.m.Input(this.getView().createId("idExtensionInput1"), {
            text : "text",
            enabled: false
        }));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM