SAPUI5 绑定问题:json 文件中维护的列表项链接不起作用
SAPUI5 binding issue: list item links maintained in json file do not work
以下情况。我在 xml 视图中定义了一个 table(文本内容位于 json 文件中)。对于每个列表项,都定义了一个按下事件,以便单击该项目将我带到另一个页面或打开一个文件。一切都正确显示,但点击事件不起作用。请提供反馈。谢谢
<VBox
id="idVBox">
<items>
<Table id="idProductsTable" inset="false"
items="{
path: '/ProductCollection',
sorter: {
path: 'Name'
}
}">
<columns>
<Column>
</Column>
</columns>
<items>
<ColumnListItem type="Navigation" press="{target}" >
<cells >
<ObjectIdentifier
title="{Name}"
class="sapMTableContentMargin" />
</cells>
</ColumnListItem>
</items>
</Table>
</items>
json 看起来像这样:
{"ProductCollection": [
{
"Name" : "blabla1",
"target" : "ee1" },
{
"Name" : "blabla2",
"target" : "ee2"
}, ....
在 js 控制器中,我定义了如下目标:
onInit: function() {
this.bus = sap.ui.getCore().getEventBus();
// set explored app's demo model on this sample
var oModel = new sap.ui.model.json.JSONModel("model/scopelist.json");
this.getView().setModel(oModel);
// Append demo table into VBox, making a minor modification
// to the first column so that the Category information is shown
var oTable = this.getView().byId("idProductsTable");
var oBindingInfo = oTable.getBindingInfo("items");
oBindingInfo.template.removeCell(0);
oBindingInfo.template.insertCell(new sap.m.ObjectIdentifier({
title: "{Name}",
text: "{Category}"
}));
oTable.bindItems(oBindingInfo);
this.getView().byId("idVBox").addItem(oTable);
}, ....
ee1: function() {
window.open("something1.pdf", "_blank");
},
ee2: function() {
window.open("./docu/something2.pdf", "_blank");
}, ...
我认为 press
事件不支持数据绑定,即允许动态函数命名。
推荐的方法是只引用命名的事件处理程序:
press="handlePress"
并在您的控制器中创建事件处理程序:
handlePress: function(oEvent) {
// get the current object from your table array
var obj = oEvent.getSource().getBindingContext().getObject();
if (obj.target === "ee1") {
//do something
}
else if (obj.target === "ee2") {
//do something else
}
}
以下情况。我在 xml 视图中定义了一个 table(文本内容位于 json 文件中)。对于每个列表项,都定义了一个按下事件,以便单击该项目将我带到另一个页面或打开一个文件。一切都正确显示,但点击事件不起作用。请提供反馈。谢谢
<VBox
id="idVBox">
<items>
<Table id="idProductsTable" inset="false"
items="{
path: '/ProductCollection',
sorter: {
path: 'Name'
}
}">
<columns>
<Column>
</Column>
</columns>
<items>
<ColumnListItem type="Navigation" press="{target}" >
<cells >
<ObjectIdentifier
title="{Name}"
class="sapMTableContentMargin" />
</cells>
</ColumnListItem>
</items>
</Table>
</items>
json 看起来像这样:
{"ProductCollection": [
{
"Name" : "blabla1",
"target" : "ee1" },
{
"Name" : "blabla2",
"target" : "ee2"
}, ....
在 js 控制器中,我定义了如下目标:
onInit: function() {
this.bus = sap.ui.getCore().getEventBus();
// set explored app's demo model on this sample
var oModel = new sap.ui.model.json.JSONModel("model/scopelist.json");
this.getView().setModel(oModel);
// Append demo table into VBox, making a minor modification
// to the first column so that the Category information is shown
var oTable = this.getView().byId("idProductsTable");
var oBindingInfo = oTable.getBindingInfo("items");
oBindingInfo.template.removeCell(0);
oBindingInfo.template.insertCell(new sap.m.ObjectIdentifier({
title: "{Name}",
text: "{Category}"
}));
oTable.bindItems(oBindingInfo);
this.getView().byId("idVBox").addItem(oTable);
}, ....
ee1: function() {
window.open("something1.pdf", "_blank");
},
ee2: function() {
window.open("./docu/something2.pdf", "_blank");
}, ...
我认为 press
事件不支持数据绑定,即允许动态函数命名。
推荐的方法是只引用命名的事件处理程序:
press="handlePress"
并在您的控制器中创建事件处理程序:
handlePress: function(oEvent) {
// get the current object from your table array
var obj = oEvent.getSource().getBindingContext().getObject();
if (obj.target === "ee1") {
//do something
}
else if (obj.target === "ee2") {
//do something else
}
}