首页 > 解决方案 > 如何从外部获取 sap.m.Select 的 selectedKey?

问题描述

拥有此选择控件:

new Select("id", {
  items: {
    path: "/cards",
    template: new ListItem({
      key: "{Kunnr}",
      text: "{Descrip}"
    }),
  },
});

我需要它能够获取它的选定键,但不能在更改事件中。我从外面需要它(另一个功能)。

我曾尝试使用该 ID,但我只是得到undefined了结果。

标签: sapui5

解决方案


selectedKey尝试使用有助于保持 MV* 模式的双向数据绑定。

new Select({
  selectedKey: "{/selectedCard}" // <-- It's TwoWay
  items: {
    path: "/cards",
    template: new ListItem({
        key: "{Kunnr}",
        text: "{Descrip}"
    }),
  },
});

我假设默认模型可以跨应用程序访问。因此,只要您可以访问该模型,您就可以通过myModel.getProperty("/selectedCard");


推荐阅读