从 UI5 控制器中单击的列表项访问绑定数据 [英] Access bound data from clicked List Item in UI5 controller

查看:29
本文介绍了从 UI5 控制器中单击的列表项访问绑定数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 UI5(XML 视图和 JS 控制器)中的输入列表项(绑定到 JSON 模型)中获取数据.

I want to fetch data from an input list item (bound to a JSON model) in UI5 (XML views & JS controller).

<List id="orderList" headerText="Menu Items: " items="{/Items}">
  <InputListltem label="{i_Category}, ({i_Points}), [{i_Category_IDA}]">
    <!-- ... -->
  </InputListltem>
</List> 

推荐答案

  1. 获取 InputListItem 的引用(例如,在其 press 处理程序中)或其任何子控件的引用,这些子控件仍具有与 InputListItem 中的绑定上下文相同的绑定上下文.

  1. Get the reference of the InputListItem (e.g. in its press-handler) or any of its child control that still has the same binding context as the one from the InputListItem.

调用getBindingContext(modelName?) 以相应的模型名称作为参数来获取绑定上下文.

Call getBindingContext(modelName?) on it with the corresponding model name as an argument to get the binding context.

从该上下文中,调用 <代码>getObject()getProperty(propertyName) 获取该列表项的绑定模型数据.例如:

From that context, call getObject() or getProperty(propertyName) to get the bound model data of that list item. For example:

<InputListItem xmlns="sap.m" press=".onItemPress" label="..."> 

{ // Controller
  onItemPress: function(event) {
    const boundContext = event.getSource().getBindingContext(/*modelName?*/);
    const data = boundContext.getObject(); /* returns: {
      i_Category: "Proteins",
      i_Points: 10,
      i_Category_ID: "PRT" 
    } */
    // Retrieve specific property value:
    const category = boundContext.getProperty("i_Category"); // returns "Proteins"
  },
}

这篇关于从 UI5 控制器中单击的列表项访问绑定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆