本文介绍了从字符串解析 XML 视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以解析 XML 字符串并将其用作 UI5 视图?

Is it possible to parse an XML string and use it as a UI5 view?

我喜欢做这样的事情:

var sXML = `<mvc:View
  xmlns:mvc="sap.ui.core.mvc"
  xmlns="sap.m"
  controllerName="controller.App"
  displayBlock="true"
>
  <App>...</App>
</mvc:View>`;

var oView = sap.ui.view({
  id: "idstart1",
  view: sXML,
  type: "XML"
});

推荐答案

截至 1.56

工厂函数 sap.ui.xmlview 现已弃用.请使用 sap.ui.core.mvc.XMLView.create[API] 而不是分配给 definition 的字符串值设置.

As of 1.56

The factory function sap.ui.xmlview is deprecated by now. Please use sap.ui.core.mvc.XMLView.create[API] instead with the string value assigned to the definition setting.

sap.ui.getCore().attachInit(() => sap.ui.require([
  "sap/ui/core/mvc/XMLView",
], XMLView => XMLView.create({
  definition:`<mvc:View
    xmlns:mvc="sap.ui.core.mvc"
    xmlns="sap.m"
    height="100%"
  >
    <App>
      <Page title="My String View">
        <Title text="Hello, world!"/>
      </Page>
    </App>
  </mvc:View>`,
}).then(view => view.placeAt("content"))));
<script>
  window["sap-ui-config"] = {
    libs: "sap.ui.core, sap.m",
    preload: "async",
    async: true,
    theme: "sap_belize",
    "xx-waitForTheme": true
  };
</script>
<script id="sap-ui-bootstrap" src="https://ui5.sap.com/resources/sap-ui-core.js"></script>
<body id="content" class="sapUiBody sapUiSizeCompact"></body>

这篇关于从字符串解析 XML 视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:42