【问题标题】:SAPUI5 binding OData v4SAPUI5 绑定 OData v4
【发布时间】: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>

【问题讨论】:

    标签: sapui5 sap-cap


    【解决方案1】:

    根据这段代码,我已经设法绑定和显示数据。我刚刚做了一些调整。

         oContextBinding.requestObject("name").then(function (sName) {
                        if (!sName) {
                            oContextBinding.getBoundContext().setProperty("name", "No name");
                        }
                    });
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-10
      • 1970-01-01
      • 2022-11-11
      • 2018-06-04
      • 2023-04-11
      相关资源
      最近更新 更多