SapUI5-如何绑定对象母版详细信息页?
我试图绑定一个元素并将其呈现给一个细节页面,但没有成功 母版页显示良好并显示数据。 但是,当我想在详细信息页面上显示项目时,数据不会显示。 *为了获取所有数据,我使用了一个API请求 我不确定我做错了什么 代码如下: Controller.Overview.jsSapUI5-如何绑定对象母版详细信息页?,sapui5,Sapui5,我试图绑定一个元素并将其呈现给一个细节页面,但没有成功 母版页显示良好并显示数据。 但是,当我想在详细信息页面上显示项目时,数据不会显示。 *为了获取所有数据,我使用了一个API请求 我不确定我做错了什么 代码如下: Controller.Overview.js var data = {id: 19265, typeId: 5, foreignKeyId: 1, foreignKeyTextId: "316e2c71-d1d1-f73c-4696-70912d6cf24
var data = {id: 19265, typeId: 5, foreignKeyId: 1, foreignKeyTextId: "316e2c71-d1d1-f73c-4696-70912d6cf240", value: 0, Name: "jim"}
,{id: 19268, typeId: 5, foreignKeyId: 1, foreignKeyTextId: "316e2c71-d1d1-f73c-4696-70912d6cf240", value: 0, Name: "john"}
var newArr2 = {"Overview" : data};
oModel.setData(newArr2);
oView.setModel(oModel);
onListItemPressed : function(oEvent){
var oItem, oCtx;
oItem = oEvent.getSource();
oCtx = oItem.getBindingContext();
this.getRouter().navTo("overviewItem",{
OverviewId : oCtx.getProperty("OverviewId")
});
}
return BaseController.extend("com.sap.it.cs.itsupportportaladmin.controller.feedbackanalytics.OverviewItem", {
_formFragments: {},
onInit: function () {
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.getRoute("overviewItem").attachMatched(this._onRouteMatched, this);
},
_onRouteMatched : function (oEvent) {
var oArgs, oView;
oArgs = oEvent.getParameter("arguments");
oView = this.getView();
oView.bindElement({
path : "/Overview(" + oArgs.OverviewId + ")",
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()) {
this.getRouter().getTargets().display("notFound");
}
}
});
Overview.xml
<List id="dataJS" headerText="dataJS" items="{/Overview}">
<items>
<StandardListItem
title="{foreignKeyTextId}"
iconDensityAware="false"
iconInset="false"
type="Navigation"
press="onListItemPressed"/>
</items>
</List>
<mvc:View
controllerName="com.sap.it.cs.itsupportportaladmin.controller.feedbackanalytics.OverviewItem"
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc"
xmlns:f="sap.ui.layout.form"
busyIndicatorDelay="0">
<Page
id="overviewPage"
title="{Name}"
showNavButton="true"
navButtonPress="onNavBack"
class="sapUiResponsiveContentPadding">
<content>
<Panel
id="employeePanel"
width="auto"
class="sapUiResponsiveMargin sapUiNoContentPadding">
<headerToolbar>
<Toolbar>
<Title text="{OverviewId}" level="H2"/>
<ToolbarSpacer />
<Link text="{i18n>FlipToResume}" tooltip="{i18n>FlipToResume.tooltip}" press="onShowResume" />
</Toolbar>
</headerToolbar>
</Panel>
</content>
</Page>
</mvc:View>
OverviewItem.xml
<List id="dataJS" headerText="dataJS" items="{/Overview}">
<items>
<StandardListItem
title="{foreignKeyTextId}"
iconDensityAware="false"
iconInset="false"
type="Navigation"
press="onListItemPressed"/>
</items>
</List>
<mvc:View
controllerName="com.sap.it.cs.itsupportportaladmin.controller.feedbackanalytics.OverviewItem"
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc"
xmlns:f="sap.ui.layout.form"
busyIndicatorDelay="0">
<Page
id="overviewPage"
title="{Name}"
showNavButton="true"
navButtonPress="onNavBack"
class="sapUiResponsiveContentPadding">
<content>
<Panel
id="employeePanel"
width="auto"
class="sapUiResponsiveMargin sapUiNoContentPadding">
<headerToolbar>
<Toolbar>
<Title text="{OverviewId}" level="H2"/>
<ToolbarSpacer />
<Link text="{i18n>FlipToResume}" tooltip="{i18n>FlipToResume.tooltip}" press="onShowResume" />
</Toolbar>
</headerToolbar>
</Panel>
</content>
</Page>
</mvc:View>
我看到两个问题:
/Overview(“+oArgs.OverviewId+”)
将不作为您的模型使用,而不是按照Controller.Overview.js中的代码作为对象:
var data = {id: 19265, typeId: 5, foreignKeyId: 1, foreignKeyTextId: "316e2c71-d1d1-f73c-4696-70912d6cf240", value: 0, Name: "jim"}
,{id: 19268, typeId: 5, foreignKeyId: 1, foreignKeyTextId: "316e2c71-d1d1-f73c-4696-70912d6cf240", value: 0, Name: "john"}
var newArr2 = {"Overview" : data};
oModel.setData(newArr2);
// this resolves to :
newArr2 = {"Overview" : [ {id: 19265...}, {id: 19268...} ]}
oView.setModel(oModel);
/Overview/“+oArgs.Overview索引
产生如下结果:Overview/0
或Overview/1
等
oView.setModel(oModel)代码>oView在Controller.Overview.js中的位置
请将模型设置为完整的拆分应用程序,以便绑定上下文正常工作
===========
讨论后更新:将数据存储为对象:
// id as the key. SO, you can easily fetch person.
var data = {
"19265" : {id: 19265, typeId: 5, foreignKeyId: 1, foreignKeyTextId: "316e2c71-d1d1-f73c-4696-70912d6cf240", value: 0, Name: "jim"},
"19268" : {id: 19268, typeId: 5, foreignKeyId: 1, foreignKeyTextId: "316e2c71-d1d1-f73c-4696-70912d6cf240", value: 0, Name: "john"}
};
并将单击时的绑定设置为:
oView.bindElement({
path : "/Overview/" + oArgs.OverviewId + "",
events : {
change: this._onBindingChange.bind(this),
dataRequested: function (oEvent) {
oView.setBusy(true);
}, ... rest of code.
好啊但是,如何保存非数组格式的数据?另外,母版页也是主页的子页,所以我想我只需要在母版页上加载数据,而不是?@Eli:Added info