XML 视图和 VizFrame 图表导航中的 SAPUI5 OData (带导航)



我正在为我的公司开发一个SAPUI5应用程序,但在基于XML的视图中使用OData(带导航)时遇到问题。有一些关于它的帖子,但我就是无法让它与 expand 属性一起使用。(如果我在基于 Js 的视图中尝试它,它会起作用)

元数据.xml

<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
<edmx:DataServices m:DataServiceVersion="1.0" m:MaxDataServiceVersion="3.0" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<Schema Namespace="TEST_SRV" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
<EntityType Name="ISSUE_B">
<Key>
<PropertyRef Name="B" />
</Key>
<Property Name="B" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false" Unicode="true" />
<Property Name="NbI" Type="Edm.Int32" Nullable="false" />
<Property Name="K1" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false" Unicode="true" />
<Property Name="I1" Type="Edm.Int32" Nullable="false" />
<Property Name="K2" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false" Unicode="true" />
<Property Name="I2" Type="Edm.Int32" Nullable="false" />
<NavigationProperty Name="B2AB_NAV" Relationship="TEST_SRV.B2AB_ASS" FromRole="FromRole_B2AB_ASS" ToRole="ToRole_B2AB_ASS" />
</EntityType>
<EntityType Name="ISSUE_AB">
<Key>
<PropertyRef Name="CId" />
<PropertyRef Name="B" />
</Key>
<Property Name="B" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false" Unicode="true" />
<Property Name="CId" Type="Edm.String" Nullable="false" Unicode="true" />
<Property Name="Open" Type="Edm.Int32" Nullable="false" Unicode="true" />
<Property Name="Closed" Type="Edm.Int32" Nullable="false" Unicode="true" />
</EntityType>
<Association Name="B2AB_ASS">
<End Type="TEST_SRV.ISSUE_B" Multiplicity="0..1" Role="FromRole_B2AB_ASS" />
<End Type="TEST_SRV.ISSUE_AB" Multiplicity="*" Role="ToRole_B2AB_ASS" />
<ReferentialConstraint>
<Principal Role="FromRole_B2AB_ASS">
<PropertyRef Name="B" />
</Principal>
<Dependent Role="ToRole_B2AB_ASS">
<PropertyRef Name="B" />
</Dependent>
</ReferentialConstraint>
</Association>
</Schema>
<Schema Namespace="ODataWebV2.My.Model" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
<EntityContainer Name="TEST_SRV_Entities" m:IsDefaultEntityContainer="true" p6:LazyLoadingEnabled="true" xmlns:p6="http://schemas.microsoft.com/ado/2009/02/edm/annotation">
<EntitySet Name="ISSUE_BSet" EntityType="TEST_SRV.ISSUE_B" />
<EntitySet Name="ISSUE_ABSet" EntityType="TEST_SRV.ISSUE_AB" />
<AssociationSet Name="B2AB_ASSSet" Association="TEST_SRV.B2AB_ASS">
<End EntitySet="ISSUE_BSet" Role="FromRole_B2AB_ASS" />
<End EntitySet="ISSUE_ABSet" Role="ToRole_B2AB_ASS" />
</AssociationSet>
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>

视图("myData"是我在清单中定义的 OData 模型)

<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:semantic="sap.m.semantic" xmlns:footerbar="sap.ushell.ui.footerbar" xmlns:viz="sap.viz.ui5.controls" xmlns:viz.data="sap.viz.ui5.data" xmlns:viz.feeds="sap.viz.ui5.controls.common.feeds"
xmlns:suite="sap.suite.ui.commons" controllerName="test.controller.DetailView" xmlns:html="http://www.w3.org/1999/xhtml" height="100%">
<Page id="detail1" title="{i18n>detailTitle}" showFooter="true" enableScrolling="false" showNavButton="true" navButtonPress="onNavBack">
<content>
<ObjectHeader title="{myData>B}" number="{myData>NbI}" numberUnit="{i18n>numberUnit}" />
<suite:ChartContainer id="idChartContainer" showFullScreen="true" showPersonalization="false" autoAdjustHeight="false" showLegend="true">
<suite:toolbar>
<OverflowToolbar id="appToolbar">
<suite:ChartContainerToolbarPlaceholder/>
</OverflowToolbar>
</suite:toolbar>
<suite:content>
<suite:ChartContainerContent icon="sap-icon://bar-chart" title="Column Chart">
<suite:content>
<viz:VizFrame uiConfig="{applicationSet:'fiori'}" id="oVizFrame1" vizType="column" width="100%" selectData="onClickVizFrame">
<viz:dataset>
<viz.data:FlattenedDataset data="{
path:'myData>/ISSUE_BSet',
parameters: {expand: 'B2AB_NAV'}
}">
<viz.data:dimensions>
<viz.data:DimensionDefinition name="Customer" value="{myData>B2AB_NAV/CId}" />
</viz.data:dimensions>
<viz.data:measures>
<viz.data:MeasureDefinition name="Closed" value="{myData>B2AB_NAV/Closed}" />
<viz.data:MeasureDefinition name="Open" value="{myData>B2AB_NAV/Open}" />
</viz.data:measures>
</viz.data:FlattenedDataset>
</viz:dataset>
<viz:feeds>
<viz.feeds:FeedItem uid="valueAxis" type="Measure" values="Open" />
<viz.feeds:FeedItem uid="valueAxis" type="Measure" values="Closed" />
<viz.feeds:FeedItem uid="categoryAxis" type="Dimension" values="Customer" />
</viz:feeds>
</viz:VizFrame>
</suite:content>
</suite:ChartContainerContent>
</suite:content>
</suite:ChartContainer>
</content>
<footer>
<Toolbar>
<content>
<ToolbarSpacer>
</ToolbarSpacer>
<Button id="__button1" icon="sap-icon://action" press="handlePopoverShare" />
</content>
</Toolbar>
</footer>
</Page>
</core:View>

控制器

sap.ui.define([
"test/controller/BaseController",
"sap/ui/model/json/JSONModel",
"sap/ui/model/Filter",
"sap/ui/model/FilterOperator"
], function(BaseController, JSONModel, Filter, FilterOperator) {
"use strict";
return BaseController.extend("test.controller.DetailView", {
onInit: function() {
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.getRoute("select").attachMatched(this._onRouteMatched, this);
},
_onRouteMatched: function(oEvent) {
var oArgs = oEvent.getParameter("arguments");
var oView = this.getView();
var oChart = oView.byId("oVizFrame2");
oChart.bindElement({
path: "/" + oArgs.domain,
model: "myData",
expand: "B2AB_NAV"
});
oView.bindElement({
path: "/" + oArgs.domain,
model: "myData",
events: {
change: this._onBindingChange.bind(this),
dataRequested: function(oEvent) {
oView.setBusy(true);
},
dataReceived: function(oEvent) {
oView.setBusy(false);
}
}
});
},
_onBindingChange: function(oEvent) {
// No data for the binding
if (!this.getView().getBindingContext("myData")) {
this.getRouter().getTargets().display("notFound");
}
},
onClickVizFrame: function(oEvent) {
var oItem = oEvent.getSource();
// Get data	
var clickedCol = oEvent.getSource().vizSelection()[0].data["_context_row_number"]
var oChart = this.getView().byId("oVizFrame1");
var aContexts = oChart.getDataset().getBinding("data").getContexts();
var sPath = aContexts[clickedCol].getPath().substr(1); //selected binding context
// Clear VizFrame Selection
var action = {
clearSelection: true
};
oItem.vizSelection("", action);
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.navTo("detail", {
data: sPath
});
},
onNavBack: function() {
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.navTo("initial", true);
}
}
});

此外,我想通过使用 VizFrame 图表导航到更多详细信息,但是如果我尝试在单击它时获取 BindingContext 路径,则只会给我导航路径,而没有以前的路径。

提前感谢您对:)的帮助

编辑:

工作压倒器示例

正如您所看到的,当您导航到第二页时,第一个图表不起作用(xml),但第二个图表(js)起作用。导航到第三页也不起作用,因为绑定上下文已更改。

我已经解决了您遇到的问题,这里是修改后的 plunker 的链接:

这是"bindObject"方法调用的示例(我把它留在这里,因为stackoverflow不允许在没有编码的情况下发布指向plnkr的链接,这对我来说很奇怪。

oView.bindObject({
path: "/" + oArgs.data,
model: "myData",
parameters: {
$expand: "B2AB_NAV"
}
});

https://plnkr.co/edit/hTSvXk1811MKdUxqfQJn

简而言之:

  1. "expand"参数在元素(对象)绑定中以错误的方式设置
  2. 视图中的绑定路径错误
  3. 细节
  4. 和细节2的路线定义具有相同的模式,这是不正确的
  5. 无需创建多个 ODataModel,默认情况下实例化的那个(基于您的 manifest.json 配置)足够强大

我没有进行重构,但有一个打磨和增强此编码的空间,正如一个人所说,请再次参考演练文档,有各种绑定类型的很好的例子..祝你好运:)

相关内容

  • 没有找到相关文章

最新更新