SAPUI5 / OPENUI5 CustomData:evt.getSource()。data()工作,this.getView()。byId(“test”)。data()不起作用

时间:2014-04-29 21:20:43

标签: sapui5

我有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:&#34; xxxxxxx&#34;}

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的源{{3}更为舒服})?

1 个答案:

答案 0 :(得分:0)

由于forEach方法返回null,因此无论使用哪种强制选择,都可以使用.data()检索数据。仅在视图内容完全加载后才能使用。

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);