【问题标题】:SAPUI5/OPENUI5 CustomData: evt.getSource().data() works, this.getView().byId("test").data() does not workSAPUI5/OPENUI5 CustomData:evt.getSource().data() 有效,this.getView().byId("test").data() 无效
【发布时间】:2014-04-29 21:20:42
【问题描述】:

我有 xml 视图(缩写):

<mvc:View controllerName="view.xxx" xmlns="sap.m" xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns:control="control" xmlns:app="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1" xmlns:h="http://www.w3.org/1999/xhtml">
...
<HBox items="{/ResourceSet}">
<Select id="myResource" app:ResourceKey="{ResourceKey}" change="handleChange"

(/ResourceSet 不产生一个条目或一个条目,仅此而已,因此 id 将始终是唯一的)

在控制器的handleChange(evt)函数内部:

evt.getSource().data()

正确生成对象 {ResourceKey: "xxxxxxx"}

this.getView().byId("myResource").data()

产生错误的对象 {ResourceKey: null}

这不好!

至少在 1.18.x 和 1.20.4 中发生。

任何想法如何访问不是当前事件源的元素的数据?

问候, 沃尔夫冈

PS http://sap.github.io/openui5/bugreports.html 要求提供 jsbin/gist:示例中是否有首选的公共 OData 源(我会更喜欢基于 NWG 的源而不是基于 MS 的源,如 http://services.odata.org/Northwind/Northwind.svc)?

【问题讨论】:

  • 当你调用 this.getView().byId("myResource").data() 时? “这个”是控制器吗? alt 尝试 sap.ui.getCore().byId("myResource").data()

标签: sapui5


【解决方案1】:

您可以使用forEach 检索数据,无论是强制选择哪个,因为.data() 方法返回null。这仅在视图内容完全加载后才有效。

var array = new Array();
this.getView().byId("myresources").getItems().forEach(function(element) {
  var keys = element.getKey();
  var texts = element.getText();
  var obj = new Object({
    key: keys,
    value: texts
  });
  array.push(obj);

});
console.log(array);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 2017-09-05
    • 2016-10-27
    • 1970-01-01
    • 2018-11-24
    • 2019-01-27
    • 1970-01-01
    相关资源
    最近更新 更多