如何使用 sap ui5 在弹出窗口中添加项目列表?
How can I add a list of items in a popover by using sap ui5?
我正在尝试在弹出窗口中添加项目列表,但不知何故不起作用:/
我用 JSON 文件中的数据填充列表。请在下面找到我的代码:
var popoverButton = new sap.ui.unified.ShellHeadItem("popoverButton",{
tooltip: "Configuration",
icon: "sap-icon://generate-shortcut",
showSeparator:false,
press:function(oEvent){
var oButton = oEvent.getSource();
if (!this._oPopover){
this._oPopover = new sap.m.Popover("popover",{
id:"pop",
placement:sap.m.PlacementType.Bottom,
showHeader:false,
contentWidth:"320px",
contentHight:"500px"
});
}
this._oPopover.openBy(oButton);
this._oPopover.addContent(oList);
return ("pop");
}
});
var oTemplate = new sap.m.StandardListItem({
title : "{title}",
icon:"{icon}",
description: "{description}",
type : sap.m.ListType.Active});
var oList = new sap.m.List({
items : {path:"/Menu", template:oTemplate}
});
这就是我在控制器中加载 JSON 文件的方式:
var oModel = new sap.ui.model.json.JSONModel("model/menu.json");
this.getView().setModel(oModel);
不幸的是弹出窗口仍然是空的:/
我认为您需要在弹出窗口上设置模型,而您目前没有这样做:
this._oPopover.setModel(oModel); //note you must do this after the model is accessible
或者,在我看来更好的方法是将弹出窗口添加为依赖视图,如下所示:
...
if (!this._oPopover){
this._oPopover = new sap.m.Popover("popover",{
id:"pop",
placement:sap.m.PlacementType.Bottom,
showHeader:false,
contentWidth:"320px",
contentHight:"500px"
});
}
//Add the popover as a view dependent, giving it access to the view model
this.getView().addDependent(this._oPopover);
...
告诉我你过得怎么样!
我正在尝试在弹出窗口中添加项目列表,但不知何故不起作用:/ 我用 JSON 文件中的数据填充列表。请在下面找到我的代码:
var popoverButton = new sap.ui.unified.ShellHeadItem("popoverButton",{
tooltip: "Configuration",
icon: "sap-icon://generate-shortcut",
showSeparator:false,
press:function(oEvent){
var oButton = oEvent.getSource();
if (!this._oPopover){
this._oPopover = new sap.m.Popover("popover",{
id:"pop",
placement:sap.m.PlacementType.Bottom,
showHeader:false,
contentWidth:"320px",
contentHight:"500px"
});
}
this._oPopover.openBy(oButton);
this._oPopover.addContent(oList);
return ("pop");
}
});
var oTemplate = new sap.m.StandardListItem({
title : "{title}",
icon:"{icon}",
description: "{description}",
type : sap.m.ListType.Active});
var oList = new sap.m.List({
items : {path:"/Menu", template:oTemplate}
});
这就是我在控制器中加载 JSON 文件的方式:
var oModel = new sap.ui.model.json.JSONModel("model/menu.json");
this.getView().setModel(oModel);
不幸的是弹出窗口仍然是空的:/
我认为您需要在弹出窗口上设置模型,而您目前没有这样做:
this._oPopover.setModel(oModel); //note you must do this after the model is accessible
或者,在我看来更好的方法是将弹出窗口添加为依赖视图,如下所示:
...
if (!this._oPopover){
this._oPopover = new sap.m.Popover("popover",{
id:"pop",
placement:sap.m.PlacementType.Bottom,
showHeader:false,
contentWidth:"320px",
contentHight:"500px"
});
}
//Add the popover as a view dependent, giving it access to the view model
this.getView().addDependent(this._oPopover);
...
告诉我你过得怎么样!