SAPUI5绑定问题:json文件中维护的列表项链接不起作用

SAPUI5 binding issue: list item links maintained in json file do not work

本文关键字:列表 项链 链接 不起作用 维护 问题 绑定 json 文件 SAPUI5      更新时间:2024-01-08

以下情况。我在xml视图中定义了一个表(文本内容位于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
    }
}