sap.m.CustomListItem 上的事件“按”不起作用

Event "press" on sap.m.CustomListItem doesn't work

本文关键字:不起作用 事件 CustomListItem sap      更新时间:2023-09-26

sap.m.CustomListItem 的 dokumentation 说 CustomListItem 会press事件。

我创建了一个网站,其中新闻事件位于列表项上,另一个

新闻事件位于列表项内的按钮上。按钮工作正常。单击列表项不显示任何内容。甚至没有错误。

var oCustomItem = new sap.m.CustomListItem({
    content: [
        new sap.m.Text({
            text: "{text}"}),
        new sap.m.Button({
            text: "btn",
            press: function(){
              alert("Pressed the button");
            }
        })
    ],
    press: function(){
      alert("Clicked the list item");
    }
});

下面是一个示例:http://jsbin.com/pozeve/4/edit?html,output

这是用户在使用列表控件时经常遇到的问题。这里有一个答案。

简而言之,您必须在CustomListItem中添加一个type属性:

var oCustomItem = new sap.m.CustomListItem({
    content: [
        new sap.m.Text({
                text: "{text}"}),
            new sap.m.Button({
                text: "btn",
                press: function(){
                    alert("Pressed the button");
                   }
                })
            ],
            type : sap.m.ListType.Active,
            press: function(){
              alert("Clicked the list item");
            }
});

mode您的sap.m.List财产。有关比较,请参阅上面提到的答案。