如何在加载视图之前从 OData 加载 2 个或更多实体
How to load 2 or more entity from OData before View is loaded
我正在开发 Master-Detail 应用程序。
我有 1 个用于主视图 (Master) 的 EntityType 和另一个用于 Detail (Detail) 的 EntityType。我创建了一个从 Master 到 Detail 的关联。
Master View 完美运行。
详细信息有 2 个部分:
- Header:显示在主视图中选择的行的几个字段。 (姓名、身份证等等)
- Body:它有2个片段。这 2 个片段显示来自详细实体的信息。
我的问题是:
- 我在控制台中遇到错误,因为加载到 Fragment 上的字段是从实体类型 Master 中搜索的。这意味着在完成第二个绑定之前加载 View && Fragments。
我尝试过的:
我使用 BusyIndicator 并控制 onInit()
中模型的事件(attachRequestComplete
and/or attachEventOnce("dataReceived")
)分配 view.setBusy(false)
到达时。它对我不起作用。
我试过了,但是当到达第二个绑定的事件时,视图已经加载。
在 Master View 中加载信息后:
function _onUpdateFinished(event) {
var sPath = selItem.getBindingContextPath().substr(1);
router.navTo("detail", {
contextPath: sPath
});
}
当我在详细视图中加载信息时:
onInit:function(){
this.getRouter().attachRoutePatternMatched(_onRoutePatternMatched, this);
},
_onRoutePatternMatched( oEvent ){
var sPath = "/" + oEvent.getParameter("arguments").contextPath;
view.bindElement({ path: sPath,
events: {
change: function (oEvent) {
},
dataRequested: function () {},
dataReceived: function (oResponse) {
view.byId("iconTabBar").bindElement({
path: "Master2Detail",
events: {
change: function (oEvents) {
},
dataRequested: function () {},
dataReceived: function (oRespon) {
view.setBusy(false);
}
}
});
}
}
});
}
非常感谢您的意见。
我正在考虑将 Header 部分的主视图中的值作为参数传递,并从后端调用详细信息实体,这样我只有 1 个调用,我假设它可以通过使用带有事件的 onInit()...
详细视图代码是:
<mvc:View xmlns="sap.m" xmlns:fsem="sap.f.semantic" xmlns:f="sap.f" xmlns:mvc="sap.ui.core.mvc" xmlns:core="sap.ui.core"
controllerName="app.masterDetail.controller.Detail">
<f:DynamicPage id="detailPage" showFooter="true" stickySubheaderProvider="iconTabBar" class="sapUiNoContentPadding">
<f:title>
<f:DynamicPageTitle>
<f:heading>
<Title text="i18n>DETAIL_VIEW" wrapping="true"/>
</f:heading>
<f:actions>
<Button id="btnTrsNew" text="{i18n>DETAIL_NEW}" type="Transparent" press="onNewFile" visible="{screenSetup>/bNewRequest}"/>
<Button id="btnTrsSave" text="{i18n>DETAIL_SAVE}" type="Transparent" press="onSaveNew" visible="{screenSetup>/bSaveCredit}"/>
<Button id="btnTrsCancel" text="{i18n>DETAIL_CANCEL}" type="Transparent" press="onCancel" visible="{screenSetup>/bCancel}"/>
</f:actions>
<f:expandedContent>
<Label text="{i18n>DETAIL_NAME}: {Name}"/>
</f:expandedContent>
<f:navigationActions>
<PagingButton id="paging" count="{ui>/paging/detailCount}" position="{ui>/paging/detailPosition}" positionChange="onPositionChange"
visible="{= ${ui>/uiState/actionButtonsInfo/midColumn/exitFullScreen} !== null || ${device>/isPhone} || ${device>/isTablet}}"/>
<Button type="Transparent" icon="sap-icon://full-screen" visible="{= ${ui>/uiState/actionButtonsInfo/midColumn/fullScreen} !== null}"
press="onFullScreenPress"/>
<Button type="Transparent" icon="sap-icon://exit-full-screen"
visible="{= ${ui>/uiState/actionButtonsInfo/midColumn/exitFullScreen} !== null}" press="onFullScreenExitPress"/>
<Button type="Transparent" icon="sap-icon://decline" visible="{= ${ui>/uiState/actionButtonsInfo/midColumn/closeColumn} !== null}"
press="onClose"/>
</f:navigationActions>
</f:DynamicPageTitle>
</f:title>
<IconTabBar id="iconTabBar" class="sapUiResponsiveContentPadding" tooltip="{i18n>DETAIL_AMOUNT}" expandable="false">
<items>
<IconTabFilter id="currentDetailTab" key="currentDetail" icon="sap-icon://business-one">
<core:Fragment id="DetailAmount" fragmentName="app.masterDetail.view.fragments.currentDetail"/>
</IconTabFilter>
<IconTabFilter id="statusDetailTab" key="statusDetail" icon="sap-icon://bbyd-active-sales" tooltip="{i18n>DETAIL_STATUS}">
<core:Fragment id="DetailStatus" fragmentName="app.masterDetail.view.fragments.statusDetail"/>
</IconTabFilter>
</items>
</IconTabBar>
</f:content>
<f:footer>
<OverflowToolbar>
<content>
<Button id="btnMessages" type="Emphasized" text="{=${messages>/}.length}" icon="sap-icon://message-popup" press="onShowMessages"
visible="{=${messages>/}.length > 0}"/>
<ToolbarSpacer/>
<Button id="btnNew" text="{i18n>DETAIL_NEW}" type="Emphasized" press="onNewFile" visible="{screenSetup>/bNewRequest}"/>
<Button id="btnSave" text="{i18n>DETAIL_SAVE}" type="Emphasized" press="onSaveNew" visible="{screenSetup>/bSaveCredit}"/>
<Button id="btnCancel" text="{i18n>DETAIL_CANCEL}" type="Reject" press="onCancel" visible="{screenSetup>/bCancel}"/>
</content>
</OverflowToolbar>
</f:footer>
</f:DynamicPage>
</mvc:View>
这将是一个带有 SmartField 的片段:
<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core" xmlns:smartForm="sap.ui.comp.smartform"
xmlns:smartField="sap.ui.comp.smartfield">
<VBox class="sapUiSmallMargin" id="creditLimitStatusVBox">
<smartForm:SmartForm id="sFormStatus" editTogglable="false" editToggled="handleEditToggled" title="{i18n>FRG_STATUS_TITLE}">
<smartForm:Group>
<smartForm:GroupElement label="{i18n>FRG_STATUS_STATUS}">
<smartField:SmartField value="{Status}"/>
</smartForm:GroupElement>
<smartForm:GroupElement label="{i18n>FRG_STATUS_ENDDATE}">
<smartField:SmartField value="{Enddate}"/>
</smartForm:GroupElement>
<smartForm:GroupElement label="{i18n>FRG_STATUS_DELIVERY}">
<smartField:SmartField value="{DeliveryId}"/>
</smartForm:GroupElement>
</smartForm:Group>
</smartForm:SmartForm>
<smartForm:SmartForm id="sFormItem" editTogglable="false" editToggled="handleEditToggled" title="{i18n>FRG_STATUS_ITEM}">
<smartForm:Group>
<smartForm:GroupElement label="{i18n>FRG_STATUS_MATERIAL}">
<smartField:SmartField value="{Material}"/>
</smartForm:GroupElement>
<smartForm:GroupElement label="{i18n>FRG_STATUS_QUANTITY}">
<smartField:SmartField value="{Quantity}"/>
</smartForm:GroupElement>
<smartForm:GroupElement label="{i18n>FRG_STATUS_AMOUNT}">
<smartField:SmartField value="{Amount}"/>
</smartForm:GroupElement>
</smartForm:Group>
</smartForm:SmartForm>
</VBox>
</core:FragmentDefinition>
看起来您的代码在详细信息方面绑定了相对路径“Master2Detail”。但最初不应在任何父视图中存在任何现有绑定。
您的应用程序的绑定路径应该大致与此类似。 UI5 正在向上移动元素以查找数据:
App-> Flexible ColumnLayout/SPlitView -> Master
App-> Flexible ColumnLayout/SPlitView -> Details
因此请按照此处所述调整您的绑定
其次,您收到此错误是因为最初在主绑定元素和详细信息之间没有相对绑定。所以UI5只能认为这一定是高手的一部分
如果你在中间编一个相对绑定,你必须自己注入片段。例如。 load the fragment, bind the loaded control(in aour case the VBox) and then use addItem 等将其附加到视图中。
我正在开发 Master-Detail 应用程序。
我有 1 个用于主视图 (Master) 的 EntityType 和另一个用于 Detail (Detail) 的 EntityType。我创建了一个从 Master 到 Detail 的关联。
Master View 完美运行。 详细信息有 2 个部分:
- Header:显示在主视图中选择的行的几个字段。 (姓名、身份证等等)
- Body:它有2个片段。这 2 个片段显示来自详细实体的信息。
我的问题是:
- 我在控制台中遇到错误,因为加载到 Fragment 上的字段是从实体类型 Master 中搜索的。这意味着在完成第二个绑定之前加载 View && Fragments。
我尝试过的:
我使用 BusyIndicator 并控制
onInit()
中模型的事件(attachRequestComplete
and/orattachEventOnce("dataReceived")
)分配view.setBusy(false)
到达时。它对我不起作用。我试过了,但是当到达第二个绑定的事件时,视图已经加载。
在 Master View 中加载信息后:
function _onUpdateFinished(event) {
var sPath = selItem.getBindingContextPath().substr(1);
router.navTo("detail", {
contextPath: sPath
});
}
当我在详细视图中加载信息时:
onInit:function(){
this.getRouter().attachRoutePatternMatched(_onRoutePatternMatched, this);
},
_onRoutePatternMatched( oEvent ){
var sPath = "/" + oEvent.getParameter("arguments").contextPath;
view.bindElement({ path: sPath,
events: {
change: function (oEvent) {
},
dataRequested: function () {},
dataReceived: function (oResponse) {
view.byId("iconTabBar").bindElement({
path: "Master2Detail",
events: {
change: function (oEvents) {
},
dataRequested: function () {},
dataReceived: function (oRespon) {
view.setBusy(false);
}
}
});
}
}
});
}
非常感谢您的意见。
我正在考虑将 Header 部分的主视图中的值作为参数传递,并从后端调用详细信息实体,这样我只有 1 个调用,我假设它可以通过使用带有事件的 onInit()...
详细视图代码是:
<mvc:View xmlns="sap.m" xmlns:fsem="sap.f.semantic" xmlns:f="sap.f" xmlns:mvc="sap.ui.core.mvc" xmlns:core="sap.ui.core"
controllerName="app.masterDetail.controller.Detail">
<f:DynamicPage id="detailPage" showFooter="true" stickySubheaderProvider="iconTabBar" class="sapUiNoContentPadding">
<f:title>
<f:DynamicPageTitle>
<f:heading>
<Title text="i18n>DETAIL_VIEW" wrapping="true"/>
</f:heading>
<f:actions>
<Button id="btnTrsNew" text="{i18n>DETAIL_NEW}" type="Transparent" press="onNewFile" visible="{screenSetup>/bNewRequest}"/>
<Button id="btnTrsSave" text="{i18n>DETAIL_SAVE}" type="Transparent" press="onSaveNew" visible="{screenSetup>/bSaveCredit}"/>
<Button id="btnTrsCancel" text="{i18n>DETAIL_CANCEL}" type="Transparent" press="onCancel" visible="{screenSetup>/bCancel}"/>
</f:actions>
<f:expandedContent>
<Label text="{i18n>DETAIL_NAME}: {Name}"/>
</f:expandedContent>
<f:navigationActions>
<PagingButton id="paging" count="{ui>/paging/detailCount}" position="{ui>/paging/detailPosition}" positionChange="onPositionChange"
visible="{= ${ui>/uiState/actionButtonsInfo/midColumn/exitFullScreen} !== null || ${device>/isPhone} || ${device>/isTablet}}"/>
<Button type="Transparent" icon="sap-icon://full-screen" visible="{= ${ui>/uiState/actionButtonsInfo/midColumn/fullScreen} !== null}"
press="onFullScreenPress"/>
<Button type="Transparent" icon="sap-icon://exit-full-screen"
visible="{= ${ui>/uiState/actionButtonsInfo/midColumn/exitFullScreen} !== null}" press="onFullScreenExitPress"/>
<Button type="Transparent" icon="sap-icon://decline" visible="{= ${ui>/uiState/actionButtonsInfo/midColumn/closeColumn} !== null}"
press="onClose"/>
</f:navigationActions>
</f:DynamicPageTitle>
</f:title>
<IconTabBar id="iconTabBar" class="sapUiResponsiveContentPadding" tooltip="{i18n>DETAIL_AMOUNT}" expandable="false">
<items>
<IconTabFilter id="currentDetailTab" key="currentDetail" icon="sap-icon://business-one">
<core:Fragment id="DetailAmount" fragmentName="app.masterDetail.view.fragments.currentDetail"/>
</IconTabFilter>
<IconTabFilter id="statusDetailTab" key="statusDetail" icon="sap-icon://bbyd-active-sales" tooltip="{i18n>DETAIL_STATUS}">
<core:Fragment id="DetailStatus" fragmentName="app.masterDetail.view.fragments.statusDetail"/>
</IconTabFilter>
</items>
</IconTabBar>
</f:content>
<f:footer>
<OverflowToolbar>
<content>
<Button id="btnMessages" type="Emphasized" text="{=${messages>/}.length}" icon="sap-icon://message-popup" press="onShowMessages"
visible="{=${messages>/}.length > 0}"/>
<ToolbarSpacer/>
<Button id="btnNew" text="{i18n>DETAIL_NEW}" type="Emphasized" press="onNewFile" visible="{screenSetup>/bNewRequest}"/>
<Button id="btnSave" text="{i18n>DETAIL_SAVE}" type="Emphasized" press="onSaveNew" visible="{screenSetup>/bSaveCredit}"/>
<Button id="btnCancel" text="{i18n>DETAIL_CANCEL}" type="Reject" press="onCancel" visible="{screenSetup>/bCancel}"/>
</content>
</OverflowToolbar>
</f:footer>
</f:DynamicPage>
</mvc:View>
这将是一个带有 SmartField 的片段:
<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core" xmlns:smartForm="sap.ui.comp.smartform"
xmlns:smartField="sap.ui.comp.smartfield">
<VBox class="sapUiSmallMargin" id="creditLimitStatusVBox">
<smartForm:SmartForm id="sFormStatus" editTogglable="false" editToggled="handleEditToggled" title="{i18n>FRG_STATUS_TITLE}">
<smartForm:Group>
<smartForm:GroupElement label="{i18n>FRG_STATUS_STATUS}">
<smartField:SmartField value="{Status}"/>
</smartForm:GroupElement>
<smartForm:GroupElement label="{i18n>FRG_STATUS_ENDDATE}">
<smartField:SmartField value="{Enddate}"/>
</smartForm:GroupElement>
<smartForm:GroupElement label="{i18n>FRG_STATUS_DELIVERY}">
<smartField:SmartField value="{DeliveryId}"/>
</smartForm:GroupElement>
</smartForm:Group>
</smartForm:SmartForm>
<smartForm:SmartForm id="sFormItem" editTogglable="false" editToggled="handleEditToggled" title="{i18n>FRG_STATUS_ITEM}">
<smartForm:Group>
<smartForm:GroupElement label="{i18n>FRG_STATUS_MATERIAL}">
<smartField:SmartField value="{Material}"/>
</smartForm:GroupElement>
<smartForm:GroupElement label="{i18n>FRG_STATUS_QUANTITY}">
<smartField:SmartField value="{Quantity}"/>
</smartForm:GroupElement>
<smartForm:GroupElement label="{i18n>FRG_STATUS_AMOUNT}">
<smartField:SmartField value="{Amount}"/>
</smartForm:GroupElement>
</smartForm:Group>
</smartForm:SmartForm>
</VBox>
</core:FragmentDefinition>
看起来您的代码在详细信息方面绑定了相对路径“Master2Detail”。但最初不应在任何父视图中存在任何现有绑定。
您的应用程序的绑定路径应该大致与此类似。 UI5 正在向上移动元素以查找数据:
App-> Flexible ColumnLayout/SPlitView -> Master
App-> Flexible ColumnLayout/SPlitView -> Details
因此请按照此处所述调整您的绑定
其次,您收到此错误是因为最初在主绑定元素和详细信息之间没有相对绑定。所以UI5只能认为这一定是高手的一部分
如果你在中间编一个相对绑定,你必须自己注入片段。例如。 load the fragment, bind the loaded control(in aour case the VBox) and then use addItem 等将其附加到视图中。