sapui5 - UI5 Routed View 与预期的绑定元素,但无法正确找到路径
问题描述
我正在尝试使用以下数据获取路由视图以显示上一个屏幕中的元素:加载到模型的 JSON 模型locationListModel
{
value: [
{
id: 251,
locationName: "SAP",
holidayList: [ ]
}
]
}
我假设我们可以locationName
使用以下路径访问第一个位置:{locationListModel>/value/0/locationName}
因此,当路由到另一个视图时,我们可以像这样访问它,或者通过执行以下操作通过视图中的元素绑定上下文来访问它:
...
onInit: function() {
this.getRouter().getRoute("location").attachMatched(this._onObjectMatched, this);
},
_onObjectMatched: function(oEvent) {
this.getView().bindElement({
path:"/value/" + oEvent.getParameter("arguments").locationId,
model:"locationListModel"});
},
...
但是,当尝试通过使用在视图中访问它时{locationName}
<Page showNavButton="true" navButtonPress="onNavBack">
<ObjectHeader title="{locationName}"/> //doesn't show
<ObjectHeader title="{locationListModel>/value/0/locationName}"/> //shows
</Page>
我们在上面的标题上什么也没有。
这是参考导航和路由演练完成的。我对 UI5 相当陌生,我似乎无法在任何地方找到此信息。我很感激任何帮助。谢谢你。
解决方案
在我看来,这个问题的提出是因为您可能参考了练习中的示例代码(上面提到的导航和路由。
如果此示例适用于在 oData 的情况下传递 URL 路径,则如果您使用的是 JSON 示例,它将无法正常工作。这会尝试将参数 invoicePath 作为“Invoices/0”发送到路由器,这是错误的,您将收到如下错误:
发生这种情况是因为路径不希望在两者之间有“/”。这个问题有一个类似的线程:Routing with parameters does not work
您可以通过仅传递路由器中的索引来解决此问题,例如
onPress: function(oEvent) {
var oItem = oEvent.getSource();
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.navTo("detail", {
//invoicePath should be the index.
invoicePath: oItem.getBindingContext("invoice").getPath().substr(10)
});
}
让我知道这是否有帮助!
推荐阅读
- react-native - 找不到 mapboxgl 的解密文件
- python - 将多行转换为一列,同时跳过以工作开头的特定行(在 python 或 shell 中)
- android - 如何将位置数据从 Firebase 提取到地图?
- c# - 排序具有项目作为字符串的 Arraylist 集合
- jenkins - 詹金斯管道“cd”命令不起作用,“cd”与“dir”?
- sql-server - 合并水晶报表中间的单元格
- node.js - 在后端获取 FormData 值?
- flutter - 如何修复 Tabbar 小部件的最后一项?
- c# - 从父按钮发送方获取图像对象
- vue.js - Nuxt.js 中的“未定义窗口”