【发布时间】:2022-10-24 20:19:36
【问题描述】:
我目前正在使用来自我的 CAP 应用程序的 OData v4 请求,问题是如何在我的简单表单中绑定我的实体请求的数据。
用户必须输入工作区代码,并搜索其值。 请问,如何绑定和显示我的工作区姓名和描述要在屏幕上显示的简单表单字段的值?
工作区 CAP 实体数据:
{
"@odata.context": "$metadata#Workspace/$entity",
"name": "Projeto Compra de Material Escritorio",
"description": "",
"projectState": "Active",
"testProject": "false",
"version": "Original",
"baseLanguage": "pt"
}
在 onInit 应用程序函数中
let oModel = new sap.ui.model.odata.v4ODataModel({
groupId : "$auto",
synchronizationMode : "None",
serviceUrl : "/myCAP_URL/"
在我的新闻事件按钮中
let oModel = this.getView().getModel();
let oContextBinding = oModel.bindContext(`/Workspace/${workspaceId}`);
oContextBinding.requestObject("name").then(function (sName) {
if (!sName) {
oContextBinding.getBoundContext().setProperty("name", "No name");
}
});
最后,这是我的简单表单字段 (XML)
<Button id="button0" press="onPress" text="Search"/>
<f:SimpleForm editable="true" layout="ResponsiveGridLayout" id="form0">
<f:content>
<sap.ui.core:Title text="{description}" id="title2"/>
<Label text="Name" id="label0"/>
<Input width="30%" id="input0" value="{name}"/>
<Label text="Language" id="label1"/>
<Input width="30%" id="input2" value="{baseLanguage}"/>
</f:content>
</f:SimpleForm>
【问题讨论】: