【问题标题】:How to read an HTML Input Field from an XML file in SAP Ui5?如何从 SAP Ui5 中的 XML 文件中读取 HTML 输入字段?
【发布时间】:2020-02-01 09:20:59
【问题描述】:

下面是 XML 视图的代码 sn-p,我可以读取 id "Name1" 但无法读取/写入 HTML 标记中的 "Name2",它返回未定义。您能帮我了解如何访问 HTML 标记中的“Name2”吗?

谢谢

sap.ui.getCore().byId("Name1").setValue(oData.FirstName + " " + oData.LastName + ); // sets the value

// Retunrs undefined
sap.ui.getCore().byId("Name2").setValue(oData.FirstName + " " + oData.LastName + ); // Sets no value
<core:FragmentDefinition
  xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc"
  xmlns:l="sap.ui.layout" xmlns:f="sap.ui.layout.form" xmlns="sap.m"
  xmlns:html="http://www.w3.org/1999/xhtml">
  <Panel class="pnlSearchDate" id="pnlContent">
    <html:span class="textcolor">
      <html:b>TITLE</html:b>
    </html:span>
    <html:br />
    <HBox alignItems="Center">
      <Label class="textcolor" width="300px" text="{i18n>txtName}" />
      <Input id="Name1" class="inputbordercolor" editable="false" width="300px"/>
    </HBox>
    <HBox justifyContent="Center">
      <VBox width="100%">
        <html:div class="textcolor"
          style="font-size: 0.875rem;font-family: Arial,Helvetica,sans-serif;line-height:25px;color:#6a7694;text-align:justify;">
          <html:p>
            I,
            <html:input class="inputEntry" id="Name2" 
              editable="false"></html:input>
            I hereby confirm that I received one session of XXX.
          </html:p>
        </html:div>
      </VBox>
    </HBox>
  </Panel>
</core:FragmentDefinition>

【问题讨论】:

标签: xml sapui5


【解决方案1】:

由于我想访问 HTML Div ID,我只是使用下面的代码来设置值并且它可以工作:

document.getElementById("Name2").value = _fullName;

【讨论】:

【解决方案2】:

尝试以下解决方案:

sap.ui.getCore().byId(this.getView().createId("Name2"));

来源:https://stackoverflow.com/a/37171149/9262488

【讨论】:

  • 不幸的是,这不起作用,因为byId-methods 只检索实时 UI5 控件。同时,来自链接源的解决方案也无法解决问题,因为 HTML 元素是在片段中定义的。访问此类元素depends on how the fragment was created.
猜你喜欢
  • 1970-01-01
  • 2019-02-22
  • 1970-01-01
  • 1970-01-01
  • 2016-06-28
  • 1970-01-01
  • 1970-01-01
  • 2023-03-23
  • 2011-04-26
相关资源
最近更新 更多