我正在尝试使用我的三个级别的OData服务在我的应用程序中构建一些sap.uxap.ObjectPageLayout。当我尝试将"块"聚合绑定为"{路径:'节点',模板:oTemplate}"时,它不会完成模板中的绑定,并且控制台会记录许多错误。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta charset="utf-8">
<title>MVC with XmlView</title>
<!-- Load UI5, select "sap_belize" theme and the "sap.m" control library -->
<script id='sap-ui-bootstrap'
src='https://sapui5.hana.ondemand.com/resources/sap-ui-core.js'
data-sap-ui-theme='sap_belize_plus'
data-sap-ui-libs='sap.m, sap.uxap'
data-sap-ui-xx-bindingSyntax='complex'></script>
<!-- DEFINE RE-USE COMPONENTS - NORMALLY DONE IN SEPARATE FILES -->
<!-- define a new (simple) View type as an XmlView
- using data binding for the Button text
- binding a controller method to the Button's "press" event
- also mixing in some plain HTML
note: typically this would be a standalone file -->
<script id="view1" type="sapui5/xmlview">
<mvc:View xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc" controllerName="my.own.controller">
<App>
<Page id="MyPage"/>
</App>
</mvc:View>
</script>
<script>
// define a new (simple) Controller type
sap.ui.controller("my.own.controller", {
// implement an event handler in the Controller
onInit: function(){
var oPage = this.getView().byId("MyPage");
oPage.bindElement("/Employees(9)")
var oOPL = new sap.uxap.ObjectPageLayout({
showTitleOnHeader: true,
showTitleInHeaderContent: true,
headerTitle: new sap.uxap.ObjectPageHeader({
isObjectTitleAlwaysVisible: false,
isObjectSubtitleAlwaysVisible: false,
objectTitle: "{FirstName} {LastName}",
objectSubtitle: "{Title}",
objectImageShape: "Circle",
objectImageURI: "https://sapui5.hana.ondemand.com/test-resources/sap/uxap/images/imageID_275314.png",
}),
headerContent: new sap.m.VBox({
items: [
new sap.m.Text({text: "{Address}"}),
new sap.m.Text({text: "{City} ({Region})"}),
new sap.m.Text({text: "{Country}"}),
]
}),
sections: [
new sap.uxap.ObjectPageSection({
title: "Orders",
subSections: {
path: "Orders",
template: new sap.uxap.ObjectPageSubSection({
title: "Order ID: {OrderID}",
blocks: {
path: "Customer",
template: this.getBlocks()
}
})
}
})
]
});
oPage.addContent(oOPL);
},
getBlocks: function(){
var oInput = new sap.m.Input({value: "{CompanyName}"})
//oInput.bindElement("Customer");
return oInput;
}
});
/*** THIS IS THE "APPLICATION" CODE ***/
// instantiate the View
var myView = sap.ui.xmlview({viewContent:jQuery('#view1').html()}); // accessing the HTML inside the script tag above
// create a Model and assign it to the View
var uri = "https://cors-anywhere.herokuapp.com/services.odata.org/Northwind/Northwind.svc"; // local proxy for cross-domain access
var oModel = new sap.ui.model.odata.ODataModel(uri, {
maxDataServiceVersion: "2.0",
useBatch: true
});
myView.setModel(oModel);
// put the View onto the screen
myView.placeAt('content');
</script>
</head>
<body id='content' class='sapUiBody'>
</body>
</html>
这里是片段:https://jsbin.com/sikihujuha/edit?html,output
我解决了每次生成模板控件时执行元素绑定的方法。但它为每个条目调用服务一次,而不是创建绑定并调用批处理请求中的所有属性。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta charset="utf-8">
<title>MVC with XmlView</title>
<!-- Load UI5, select "sap_belize" theme and the "sap.m" control library -->
<script id='sap-ui-bootstrap'
src='https://sapui5.hana.ondemand.com/resources/sap-ui-core.js'
data-sap-ui-theme='sap_belize_plus'
data-sap-ui-libs='sap.m, sap.uxap'
data-sap-ui-xx-bindingSyntax='complex'></script>
<!-- DEFINE RE-USE COMPONENTS - NORMALLY DONE IN SEPARATE FILES -->
<!-- define a new (simple) View type as an XmlView
- using data binding for the Button text
- binding a controller method to the Button's "press" event
- also mixing in some plain HTML
note: typically this would be a standalone file -->
<script id="view1" type="sapui5/xmlview">
<mvc:View xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc" controllerName="my.own.controller">
<App>
<Page id="MyPage"/>
</App>
</mvc:View>
</script>
<script>
// define a new (simple) Controller type
sap.ui.controller("my.own.controller", {
// implement an event handler in the Controller
onInit: function(){
var oPage = this.getView().byId("MyPage");
oPage.bindElement("/Employees(9)")
var oOPL = new sap.uxap.ObjectPageLayout({
showTitleOnHeader: true,
showTitleInHeaderContent: true,
headerTitle: new sap.uxap.ObjectPageHeader({
isObjectTitleAlwaysVisible: false,
isObjectSubtitleAlwaysVisible: false,
objectTitle: "{FirstName} {LastName}",
objectSubtitle: "{Title}",
objectImageShape: "Circle",
objectImageURI: "https://sapui5.hana.ondemand.com/test-resources/sap/uxap/images/imageID_275314.png",
}),
headerContent: new sap.m.VBox({
items: [
new sap.m.Text({text: "{Address}"}),
new sap.m.Text({text: "{City} ({Region})"}),
new sap.m.Text({text: "{Country}"}),
]
}),
sections: [
new sap.uxap.ObjectPageSection({
title: "Orders",
subSections: {
path: "Orders",
template: new sap.uxap.ObjectPageSubSection({
title: "Order ID: {OrderID}",
blocks: this.getBlocks()
})
}
})
]
});
oPage.addContent(oOPL);
},
getBlocks: function(){
//var oInput = new sap.m.Input({value: "{Customer/CompanyName}"})
var oInput = new sap.m.Input({value: "{CompanyName}"})
oInput.bindElement("Customer");
return [oInput];
}
});
/*** THIS IS THE "APPLICATION" CODE ***/
// instantiate the View
var myView = sap.ui.xmlview({viewContent:jQuery('#view1').html()}); // accessing the HTML inside the script tag above
// create a Model and assign it to the View
var uri = "https://cors-anywhere.herokuapp.com/services.odata.org/Northwind/Northwind.svc"; // local proxy for cross-domain access
var oModel = new sap.ui.model.odata.ODataModel(uri, {
maxDataServiceVersion: "2.0",
useBatch: true
});
myView.setModel(oModel);
// put the View onto the screen
myView.placeAt('content');
</script>
</head>
<body id='content' class='sapUiBody'>
</body>
</html>
此处解决方法:https://jsbin.com/zajacodoce/edit?html,output
有什么想法可以改善这一点吗?
谢谢和问候,拉斐尔·洛佩兹
很好,我在解决方法的代码中发现了一个错误。我没有正确扩展第一个元素绑定,它应该是:$expand=订单/客户我想这是我测试中的一个错字。
无论如何,第一个代码段不起作用,似乎 Blocks 聚合包含指向 url 的另一个"$expand"参数,并且错误出现在控制台中