我已经创建了下拉菜单。事件新闻我有问题。我想按菜单时从JSON获取上下文。
JSON:
dropdownMenu: {
kepesertaan:[
{
name: "Menu1",
icon: "sap-icon://crop",
sub: [
{
name: "Submenu1-1",
icon: "sap-icon://create-session"
},
{
name: "Submenu1-2",
icon: "sap-icon://create-form"
}
]
},
{
name: "Menu2",
icon: "sap-icon://detail-view",
sub: [
{
name: "Submenu2-1",
icon: "sap-icon://add-activity"
},
{
name: "Submenu2-2",
icon: "sap-icon://action"
}
]
},
{
name: "Menu3",
icon: "sap-icon://delete",
sub: [
{
name: "Submenu3-1",
icon: "sap-icon://add-favorite"
},
{
name: "Submenu3-2",
icon: "sap-icon://add-document"
}
]
}
]
}
JS:
handleMenuItemPressKepesertaan: function(oEvent) {
var app = sap.ui.getCore().byId("menuEventingKepesertaan");
var oModel = app.getModel("kepesertaanmodel");
var oContext = oModel.getProperty("/1"); // get context from property by path
alert(oContext.name);
// alert(oContext.sub[0].name);
var bindingContext = sap.ui.getCore().getBindingContext();
var path = bindingContext.getPath();
alert(path);
}
我试过并警告路径但失败了。 getPath()不是函数或未定义。 此路径将更改代码“var oContext = oModel.getProperty(”/ 1“);”。值“/ 1”是一条路径。以及如何解决这个问题?有关信息,片段xml中的菜单。