javascript - SAPUI5绑定(bind)问题: list item links maintained in json file do not work

标签 javascript json binding sapui5

以下情况。我有一个在 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/

相关文章:

javascript - 让一个 div 容器变得不可见

javascript - 如何使用 jQuery 在新选项卡或窗口中捕获打开的链接?

javascript - 如何将 JavaScript 对象转换为 LITERAL 字符串?

html - 适用于结构化数据的文本友好文件格式

c# - 使用不同的 UpdateSourceTrigger 进行验证和转换

javascript - 使用 Node.js 如何设置 var 来响应 HTTP 客户端?

c# - 在 C# 中将 json 字符串写入 firestore

java - 使用 Spring 和 JsonTypeInfo 注释将 JSON 反序列化为多态对象模型

c# - 使用绑定(bind)设置用户控件中文本框的文本属性 - WPF

cocoa - 如何使用绑定(bind)在基于 NSTableView 的 View 中启用/禁用编辑?