2017-07-03 23 views
0

我想動態加載一個片段,並具有以下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 

我在做什麼錯在這裏?

+0

請參考[鏈接](https://sapui5.hana.ondemand.com/sdk/#docs/guide/65da02badf704e03a4fd6bd4c5aba8f4.html),這可能會幫助您實現您正在尋找的內容 – Prashob

+0

謝謝!我以前就已經知道這個頁面,但不知何故它不適用於我:-( – masrlinu

+0

)爲什麼不按照參考鏈接中的說明使用格式化程序?它在sapui5 sdk的開發人員指南選項卡中有詳細記錄。通過比較您的代碼 – Prashob

回答

0

我不認爲你可以使用表達式綁定屬性'fragmentName',就像你不能'ID'或'類'你應該使用格式化函數。

+0

SAP不使用表達式綁定在[本示例]中屬性'fragmentName'(https://sapui5.hana.ondemand.com/sdk/#docs/guide/65da02badf704e03a4fd6bd4c5aba8f4.html)? 他們使用格式化程序,但執行==='true '比較並使用條件運算符(test?'fragment1':'fragment2')。 – masrlinu

+0

是的,該示例顯示瞭如何將fragmentName綁定到模型porperty或表達式ñ,但它不起作用! 也只是綁定到一個模型屬性,如: 將引發錯誤。比日誌顯示 清楚地表明該表達式不被計算,而是作爲字符串處理 – gaugeinvariante