不显示对象页面字段

问题描述 投票:0回答:1

我正在使用 Fiori 自由式开发来满足需求,使用 CDS 视图作为数据源,我创建了一个列表页面,单击任何项目都会导航到详细信息页面,但数据未显示。

请找到控制器并查看详细信息/对象页面,我这里缺少什么吗?

sap.ui.define([
    'sap/ui/core/mvc/Controller',
    'sap/ui/model/odata/v2/ODataModel',
    'sap/ui/model/Filter',
    'sap/ui/core/util/MockServer',
    'sap/m/MessageToast',
    'sap/ui/core/routing/History',
], function (Controller, ODataModel, Filter) {
    "use strict";
    return Controller.extend("myapp.controller.DisplayRequest", {
        onInit: function () {
            var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
            oRouter.getRoute("DisplayRequest").attachMatched(this._onRouteMatched, this);
        },     
        _onRouteMatched: function (oEvent) {
            var oArgs = oEvent.getParameter("arguments");
            var reqid = oArgs.Reqid;
            this._fetchData(reqid);
        }     
        _fetchData: function (reqid) {
            
            var oData = this.getView().getModel().read("/myCDSView", {
                filters: [new sap.ui.model.Filter("reqid", sap.ui.model.FilterOperator.EQ, reqid)],
                success: function (oData) {
                    var oModel = new sap.ui.model.json.JSONModel(oData);
                    this.getView().setModel(oModel, "data");
                }.bind(this),
                error: function (oError) {
                    // Handle error
                }
            });
        }
        
    });
});
<mvc:View controllerName="myapp.controller.DisplayRequest" height="100%"
    xmlns:mvc="sap.ui.core.mvc" displayBlock="true" xmlns="sap.m"
    xmlns:core="sap.ui.core" xmlns:smartFilterBar="sap.ui.comp.smartfilterbar"
    xmlns:smartTable="sap.ui.comp.smarttable" xmlns:uxap="sap.uxap" xmlns:form="sap.ui.comp.smartform"
    xmlns:smart="sap.ui.comp.smartfield">

    <uxap:ObjectPageLayout>
        <uxap:headerTitle>
        </uxap:headerTitle>
        <uxap:sections>
            <uxap:ObjectPageSection
                titleUppercase="false" id="idGeneralInfo" title="General Info">
                <uxap:subSections>
                    <uxap:ObjectPageSubSection   title="General Info" titleUppercase="false">
                        <form:SmartForm
                            id="SF1" class="editableForm" editTogglable="false" editable="true">
                            <form:Group id="G1">
                                <form:GroupElement id="GE-Cocode">
                                    <smart:SmartField id="idCocode" value="{data>company_code}"/>
                                </form:GroupElement>
                            </form:Group>

                            <form:Group id="G2"> <form:GroupElement id="GE-Vendor">
                                    <smart:SmartField id="idVendor" value="{data>vendor}"/>
                                </form:GroupElement>
                            </form:Group>
                        </form:SmartForm>
                    </uxap:ObjectPageSubSection>
                </uxap:subSections>
            </uxap:ObjectPageSection>
        </uxap:sections>
    </uxap:ObjectPageLayout>
</mvc:View>
sapui5 sap-fiori
1个回答
0
投票

我做了以下操作并找到了解决方案

onInit: function () {
            var oRouter = sap.ui.core.UIComponent.getRouterFor(this);               oRouter.getRoute("DisplayRequest").attachMatched(this._onRouteMatched.bind(this));
        },
        _onRouteMatched : function (oEvent) {
            var that = this;
            var oArgs, oView;
            oView = this.getView();
            oArgs = oEvent.getParameter("arguments");
            var reqid = oArgs.reqid;
            
            this.getView().getModel().metadataLoaded().then(function() {
                var sPath = that.getView().getModel().createKey("/entityset", {
                    reqid: reqid
                });
                that.getView().bindElement({
                    path:sPath,
                    events: {
                        change:function(oEvent){
                             that.getView().getBindingContext();
                        },
                        dataRequested: function() {
                            that.getView().setBusy(true);
                        },
                        dataReceived: function(oData) {
                            that.getView().setBusy(false);
© www.soinside.com 2019 - 2024. All rights reserved.