SAPUI5 - 如何从细节视图中获取扩展上下文

SAPUI5 - How to get expanded context from detail view

我试图从详细视图中的扩展实体获取上下文,但是当我使用扩展参数时,它只有 returns 键列表。我试过使用 oModel.read 和列表中给定的键,但没有成功。

谁能帮我解决这个问题?

这是我的代码:

onInit : function () {
    var oViewModel = new JSONModel({
        busy : false,
        delay : 0,
        lineItemListTitle : this.getResourceBundle().getText("detailLineItemTableHeading")
    });

    this.getRouter().getRoute("object").attachPatternMatched(this._onObjectMatched, this);

    this.setModel(oViewModel, "detailView");

    this.getOwnerComponent().getModel().metadataLoaded().then(this._onMetadataLoaded.bind(this));

},

_onObjectMatched : function (oEvent) {
    var sObjectId =  oEvent.getParameter("arguments").objectId;

    this.getModel("appView").setProperty("/layout", "TwoColumnsMidExpanded");
    this.getModel().metadataLoaded().then( function() {
        var sObjectPath = this.getModel().createKey("Categories", {
            CategoryID :  sObjectId
        });
        this._bindView("/" + sObjectPath);
    }.bind(this));
},


_bindView : function (sObjectPath) {
    // Set busy indicator during view binding
    var oViewModel = this.getModel("detailView");

    oViewModel.setProperty("/busy", false);

        this.getView().bindElement({
        path : sObjectPath,
        parameters : {
            expand: "Products"
        },
        events: {
            change : this._onBindingChange.bind(this),
            dataRequested : function () {
                oViewModel.setProperty("/busy", true);
            },
            dataReceived: function () {
                oViewModel.setProperty("/busy", false);
            }
        }
    });
},

_onBindingChange : function () {
    var oView = this.getView(),
        oElementBinding = oView.getElementBinding();


    // No data for the binding
    if (!oElementBinding.getBoundContext()) {
        this.getRouter().getTargets().display("detailObjectNotFound");
        // if object could not be found, the selection in the master list
        // does not make sense anymore.
        this.getOwnerComponent().oListSelector.clearMasterListSelection();
        return;
    }

    var sPath = oElementBinding.getPath(),
        oResourceBundle = this.getResourceBundle(),
        oObject = oView.getModel().getObject(sPath),
        sObjectId = oObject.CategoryID,
        sObjectName = oObject.CategoryName,
        oViewModel = this.getModel("detailView"),
        oBindingContext = this.getView().getBindingContext().getObject();

        console.log("Object ", oObject);

    this.getOwnerComponent().oListSelector.selectAListItem(sPath);

        oViewModel.setProperty("/shareSendEmailSubject",
    oResourceBundle.getText("shareSendEmailObjectSubject", [sObjectId]));
    oViewModel.setProperty("/shareSendEmailMessage",
    oResourceBundle.getText("shareSendEmailObjectMessage", [sObjectName, sObjectId, location.href]));
},

并且输出:

output

预期输出:

expected output

这就是 ODataModel 存储信息的方式。

如果您读取带有扩展参数的 EntitySet,它将请求所有这些数据。 但在实体 "Category(1)" 中,它仅将 Reference/Path 存储到产品实体。

通过。 this.getView().getModel().getProperty("/" + "Products(1)") 您访问实体对象。

通过。 this.getView().getModel().getProperty("/") 您可以访问服务模型请求的所有实体,包括。您的产品实体。

您到底不想达到什么目的?