0
我在SplitApp中將主參數傳遞給詳細信息頁面時遇到了一些問題。我使用在manifest.json中指定爲模型的本地JSON文件。SAP UI5:master-detail參數傳遞問題
我可以傳遞一個對象的Id,但在這種情況下,我無法弄清楚,如何在詳細視圖中接收相應的元素,將其綁定到視圖。
我也嘗試過傳遞元素的路徑,但是在這種情況下,在我選擇一個列表項後url不會改變。
任何想法,我如何能夠顯示細節頁面上的細節?
的manifest.json:
...
"models": {
"items": {
"type": "sap.ui.model.json.JSONModel",
"uri": "model/items.json"
}
},
"routing": {
"config": {
"controlId": "rootControl",
"viewPath": "my.try.view",
"viewType": "XML",
"async": true
},
"routes" : [
{
"pattern" : "",
"name" : "master",
"target" : ["detail", "master"]
},
{
"pattern": "detail/{Id}",
"name":"detail",
"target": ["master", "detail"]
}
],
"targets" : {
"master" : {
"viewName" : "Master",
"controlAggregation" : "masterPages"
},
"detail" : {
"viewName" : "Detail",
"controlAggregation" : "detailPages"
}
}
}...
Master.view.xml
<mvc:View controllerName="my.try.controller.Master" xmlns:semantic="sap.m.semantic" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m">
<semantic:MasterPage title="Persons">
<List id="idList" items="{items>/item}" selectionChange="onItemPressed" mode="SingleSelectMaster">
<items>
<ObjectListItem title="{item>Date}">
<firstStatus>
<ObjectStatus text="{item>Status}"/>
</firstStatus>
</ObjectListItem>
</items>
</List>
</semantic:MasterPage>
</mvc:View>
Master.controller.js
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/model/json/JSONModel"
], function(Controller, JSONModel) {
"use strict";
return Controller.extend("my.try.controller.Master", {
onInit: function() {
this.oRouter = this.getOwnerComponent().getRouter();
},
onItemPressed: function(oEvent) {
// When I try with the path, nothing happens. Only passing the Id works!?
// var oItemID = oEvent.getParameter("listItem").getBindingContext("items").getPath().substr(1);
var oItemID = oEvent.getParameter("listItem").getBindingContext("items").getProperty("Id");
this.oRouter.navTo("detail", {
Id: oItemID
});
}
});
});
Detail.view.xml
<mvc:View controllerName="my.try.controller.Detail" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:semantic="sap.m.semantic">
<semantic:DetailPage title="Detail">
<ObjectHeader title="{ItemName}"/>
</semantic:DetailPage>
</mvc:View>
個
Detail.controller.js
sap.ui.define([
"sap/ui/core/mvc/Controller"
], function(Controller) {
"use strict";
return Controller.extend("my.try.controller.Detail", {
onInit: function() {
this.oRouter = this.getOwnerComponent().getRouter();
this.oRouter.getRoute("detail").attachPatternMatched(this._onDetailRouteHit, this);
},
_onDetailRouteHit: function(oEvent) {
var sID = oEvent.getParameter("arguments").Id;
//The parameter is passed
alert(sID);
//This doesn't work. How can I do this withou having a service?
this.getView().getModel().metadataLoaded().then(function() {
var sObjectPath = this.getView().getModel().createKey("ItemSet", {
Id : sID
});
this.getView().bindElement({
path: "/" + sObjectPath
});
}.bind(this));
}
});
});
好,感謝的提示!看來,這個模型並不適合這個觀點。我得到一個錯誤:「未捕獲(承諾)類型錯誤:無法讀取未定義的屬性'getProperty'我雖然通過在描述符中定義模型,模型應該可以在整個應用程序中使用,我錯了嗎? – manban
您是否正在初始化路由器在你的組件'init()'中調用基類的'init()'方法之後?在base.init()調用之後放置一個斷點並驗證模型在組件上是否可用,視圖應該繼承該組件 – schnoedel
啊,我剛剛意識到你的模型被命名爲* items *。你必須給getModel()方法命名並在元素綁定中爲模型添加前綴 – schnoedel