0

我想向我的列表组件触发上下文菜单事件。我正在使用以下编码,但它不起作用。我在哪里做错了?请让我知道我应该如何正确使用此事件。这是我的代码;我的列表组件:

<List
   id="commentListView"
   items="{/TicketItemModel/COMMENTS}"
   visible="{/TicketCommentListVisibility}"
   mode="SingleSelectMaster"
   includeItemInSelection="true"
   class="todo-comment-list">
   {/* Items here.. */}
</List>

我的 controller.js 文件:

this.getView().byId("commentListView").attachBeforeOpenContextMenu(??,_this.handleShowCommentContextMenu(),??);

我不确切知道应该将哪些参数传递给函数

这是我调用的主要功能代码:

handleShowCommentContextMenu:function(oEvent){
          var _this = this;
          if(oEvent){
            var listItemBase = oEvent.getSource();
            if(!_this.popupMenu){
              _this.popupMenu = new Menu({
                items:[
                  new sap.ui.unified.MenuItem({
                    text:"Settings",
                    select:function(){
                    }
                  }),
                ]
              })
              _this.getView().addDependent(_this.popupMenu);
            }
            var eDock = sap.ui.core.Popup.Dock;
            _this.popupMenu.open(false, listItemBase, eDock.BeginTop, eDock.BeginBottom, listItemBase);
          }
        }
4

2 回答 2

0

正如您可以在此处阅读的:
https ://sapui5.hana.ondemand.com/1.54.8/#/api/sap.m.ListBase/methods/attachBeforeOpenContextMenu

该函数的参数如下:

attachBeforeOpenContextMenu(oData?, fnFunction, oListener?)

?一个和第三个参数后面是可选的指标。
这意味着,即使没有它们,您的代码也可以正常工作。

oListener是一个对象(如链接中的文本所示)将事件置于上下文中。您甚至可以在代码中使用默认值sap.m.ListBase( oEvent)

用于调用事件处理程序的上下文对象。默认为此 sap.m.ListBase 本身

oData是那种模型端来的oListener。虽然oListener是将事件放入上下文的控制元素,但oData对象是将事件放入上下文的数据。

我希望我能为你澄清事情。

于 2018-10-23T05:52:21.653 回答
0

为了在列表项上打开上下文菜单。首先你需要定义菜单。然后您可以将 beforeOpenContextMenu 事件设置为 XmlView 中的列表组件。

_this.getView().byId("commentListView").setContextMenu(new Menu({
     items:[
          new sap.ui.unified.MenuItem({
          text:"Settings",
          select:function(){
          }
       }),
     ]
}))
于 2018-10-23T07:28:28.433 回答