本文介绍了获取所选项目的详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 sap.m.ObjectListItem 作为我的列表项,我已将来自 API 的 JSON 数据绑定到这些项.但是,当我按下某个项目时,我找不到从列表中获取所选项目的方法.即使得到那个项目的钥匙也会有帮助.

I am using the sap.m.ObjectListItem as my list items to which I have bound JSON data from an API. However, I can't find a way to get the selected item from the list when I press on an item. Even getting the key of that item would be helpful.

<List id="ObjectList"
  itemPress=".onPressDcData"
  items="{DC>/}"
>
  <ObjectListItem
    type="Active"
    title="{DC>Name}"
  />
</List>

推荐答案

以下应该放在你各自的控制器中(但我猜你已经实现了类似的东西)

The following should be placed in your respective controller (but I guess you already have implemented something similar)

onPressDcData: function(oEvent) {
    // The actual Item
    var oItem = oEvent.getSource();
    // The model that is bound to the item
    var oContext = oItem.getBindingContext("DC");
    // A single property from the bound model
    var sName = oContext.getProperty("Name");
}

希望有帮助

这篇关于获取所选项目的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 15:52
查看更多