簡體   English   中英

如何在表達式綁定中使用三元運算符切換應用屬性綁定?

[英]How to switch applying a property binding using ternary operator in Expression Binding?

看,我有一個表格,其中使用sap.m.Tablehighlight屬性突出顯示了重復的條目。 現在我正在嘗試實現一個切換按鈕,讓用戶決定是否要突出顯示重復項。

在我的 controller 中,我創建了切換按鈕 function,它切換綁定到我的表的客戶端 model“compareModel”的 model 屬性“compare”。

我的默認 model 是表項的 model。 綁定的“dupe”屬性包含"Success""Error"

這有效:

<ColumnListItem highlight="{dupe}">
  <Text text="{myItemText}" />
  <!-- ... -->
</ColumnListItem>

現在我的問題:

我想根據是否按下切換按鈕來設置highlight屬性。 到目前為止,我的 表達式綁定嘗試看起來像這樣:

<ColumnListItem highlight="{= ${compareModel>/compare} ? ${dupe} : false }">

我試着在這里和那里加上引號,但到目前為止沒有運氣。 希望有人能幫助我!

嘗試使用highlight="{= ${compareModel>/compare}? ${dupe}: undefined }

工作樣本:

 globalThis.onUI5Init = () => sap.ui.require([ "sap/ui/core/mvc/XMLView", "sap/ui/model/json/JSONModel", // sample model. Applies also to ODataModel ], async function (XMLView, JSONModel) { "use strict"; const control = await XMLView.create({ definition: `<mvc:View xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" displayBlock="true" height="100%" > <App> <Page title="Toggle Highlight"> <headerContent> <Switch state="{compareModel>/compare}" customTextOn=" " customTextOff=" " /> </headerContent> <List items="{/items}"> <StandardListItem title="{myItemText}" highlight="{= %{compareModel>/compare}? %{dupe}: undefined }" /> </List> </Page> </App> </mvc:View>`, models: { "compareModel": new JSONModel({ "compare": true }), undefined: new JSONModel({ "items": [ { "myItemKey": 1, "myItemText": "A", "dupe": "Error" }, { "myItemKey": 2, "myItemText": "B", "dupe": "Success" }, { "myItemKey": 3, "myItemText": "A", "dupe": "Error" } ] }), }, }); control.placeAt("content"); });
 <script id="sap-ui-bootstrap" src="https://sdk.openui5.org/resources/sap-ui-core.js" data-sap-ui-libs="sap.ui.core,sap.m,sap.ui.layout,sap.ui.unified" data-sap-ui-async="true" data-sap-ui-oninit="onUI5Init" data-sap-ui-theme="sap_horizon" data-sap-ui-compatversion="edge" data-sap-ui-excludejquerycompat="true" data-sap-ui-xx-waitfortheme="init" ></script> <body id="content" class="sapUiBody"></body>

highlight="{=... ? ... : false }"的問題是false不是列表項的highlight屬性的枚舉sap.ui.core.MessageType / .IndicationColor中的有效值。 您應該會看到控制台錯誤報告類似的問題。

但是,對於undefined ,將應用highlight的默認值,sap.m.ListBase控件的"None"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM