以下情况。我有一个在 xml View 中定义的表(文本内容位于 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 Controller 中,我定义了如下目标:
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
事件不支持数据绑定(bind),即允许动态函数命名。
推荐的方法是仅引用命名的事件处理程序:
press="handlePress"
并在您的 Controller 中创建事件处理程序:
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
}
}
关于javascript - SAPUI5绑定(bind)问题: list item links maintained in json file do not work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28566847/