如标题所示,我确实有以下数据。
{
"modelExample": [
{ "id": 0 },
{ "id": 1 },
{ "id": 2 }
]
}
JSONModel有3个条目,基本上等同于 3
在 length
.
我如何通过一个 表达式结合 声明?
我的尝试。
<Text text="{ ${modelExample>/}.length}"
好了,这里有一个例子。点击 运行代码片段 来看看它的行动。
sap.ui.require([
"sap/ui/core/Core",
], Core => Core.attachInit(() => sap.ui.require([
"sap/ui/core/Fragment",
"sap/ui/model/json/JSONModel",
], async (Fragment, JSONModel) => {
"use strict";
// sample XML definition:
const definition = '<ObjectStatus title="Length" text="{= ${/modelExample}.length}" class="sapMObjectStatusLarge sapUiTinyMargin" inverted="true" state="Information" xmlns="sap.m" />';
const control = await Fragment.load({ definition });
const model = new JSONModel({
modelExample: [
{ id: 0, /*...*/},
{ id: 1, /*...*/},
{ id: 2, /*...*/},
],
});
control.setModel(model).placeAt("content");
})));
<script id="sap-ui-bootstrap" src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-libs="sap.ui.core, sap.m"
data-sap-ui-async="true"
data-sap-ui-compatversion="edge"
data-sap-ui-theme="sap_fiori_3"
data-sap-ui-xx-waitfortheme="init"
></script>
<body id="content" class="sapUiBody"></body>
如你所见,我使用的是 text="{= ${/modelExample}.length}"
显示数组的正确长度。
"myModel"
),它应该是 {= ${myModel>/modelExample}.length}
.{=
(OneWay)或 {:=
(OneTime)开头。bindingSyntax
需要设置为 "complex"
或 compatVersion
到 "edge"
如本报告所述 岗位. 例如,在 index.html
:<script id="sap-ui-bootstrap" data-sap-ui-compatversion="edge" ...>