我想动态加载一个片段,并具有以下XML-查看:sapui5 - 动态加载片段插入XML-查看
<mvc:View
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:core="sap.ui.core"
xmlns:mvc="sap.ui.core.mvc"
xmlns:l="sap.ui.layout"
xmlns="sap.m"
controllerName="controller.App"
visibleBlock="true">
<App>
<pages>
...
<core:Fragment fragmentName="{= ${/BOOL_VALUE} === 'true' ? 'view.fragment1' : 'view.fragment2'}" type="XML" />
...
</pages>
</App>
</mvc:View>
,但不知何故,当我打开它,里面fragmentName的表达没有得到评估和比较得到像文件名一样对待:
Uncaught (in promise) Error: resource {= ${/BOOL_VALUE} === 'true' ? 'view/fragment1' : 'view/fragment2'}.fragment.xml could not be loaded from https://sapui5.hana.ondemand.com/1.44.14/resources/{= ${/BOOL_VALUE} === 'true' ? 'view/fragment1' : 'view/fragment2'}.fragment.xml. Check for 'file not found' or parse errors. Reason: NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'https://sapui5.hana.ondemand.com/1.44.14/resources/%7B=%20$%7B/BOOL_VALUE%7…'true'%20?%20%27view/fragment1%27%20:%20%27view/fragment2%27}.fragment.xml'.
at Object.error (jquery.sap.global-dbg.js:4573)
at p (jquery-dbg.js:3187)
at Object.fireWith [as rejectWith] (jquery-dbg.js:3317)
at h3 (jquery-dbg.js:8787)
at Function.ajax (jquery-dbg.js:8689)
at Object.q.sap.loadResource (jquery.sap.global-dbg.js:4564)
at Object.X.loadTemplate (XMLTemplateProcessor-dbg.js:64)
at constructor.init (Fragment-dbg.js:469)
at constructor.F._initCompositeSupport (Fragment-dbg.js:135)
at ManagedObject-dbg.js:427
我在做什么错在这里?
请参考[链接](https://sapui5.hana.ondemand.com/sdk/#docs/guide/65da02badf704e03a4fd6bd4c5aba8f4.html),这可能会帮助您实现您正在寻找的内容 – Prashob
谢谢!我以前就已经知道这个页面,但不知何故它不适用于我:-( – masrlinu
)为什么不按照参考链接中的说明使用格式化程序?它在sapui5 sdk的开发人员指南选项卡中有详细记录。通过比较您的代码 – Prashob