Sapui5 如何从外部获取sap.m.Select的selectedKey?
具有此选择控件:Sapui5 如何从外部获取sap.m.Select的selectedKey?,sapui5,Sapui5,具有此选择控件: var myvar = sap.ui.getCore().getModel("marcas"); var selectedKey= myvar.getProperty('/cards/Kunnr'); newselect(“id”{ 项目:{ 路径:“/cards”, 模板:新列表项({ 密钥:“{Kunnr}”, 正文:“{Descrip}” }), }, }); 我需要它能够获得它的选择键,但不能在更改事件中。我需要它从外部(另一个功能) var myvar = sap
var myvar = sap.ui.getCore().getModel("marcas");
var selectedKey= myvar.getProperty('/cards/Kunnr');
newselect(“id”{
项目:{
路径:“/cards”,
模板:新列表项({
密钥:“{Kunnr}”,
正文:“{Descrip}”
}),
},
});
我需要它能够获得它的选择键,但不能在更改事件中。我需要它从外部(另一个功能)
var myvar = sap.ui.getCore().getModel("marcas");
var selectedKey= myvar.getProperty('/cards/Kunnr');
我尝试使用ID,但结果是
未定义。您的问题中缺少一些信息,主要是关于如何将oSelectMarca
添加到您的视图中。这会改变它在应用程序中的可用性。有两个地方可以通过Id获取内容:
this.getView().byId('id');
sap.ui.getCore().byId('id');
var myvar = sap.ui.getCore().getModel("marcas");
var selectedKey= myvar.getProperty('/cards/Kunnr');
你得检查一下是哪一个。。。另一种选择是将该模型添加到视图中,而不是oSelectMarca
,在这种情况下,您的视图和您的选择可以共享数据。但这同样取决于如何将select添加到屏幕 根据您需要在何处使用,您可以执行以下操作:
this.oSelectMarca = new sap.m.Select('id',{});
this.oSelectMarca.setModel(myModel);
var myvar = sap.ui.getCore().getModel("marcas");
var selectedKey= myvar.getProperty('/cards/Kunnr');
或者,如果要在其他控制器中使用,请尝试:
sap.ui.getCore().oSelectMarca = new sap.m.Select('id',{});
sap.ui.getCore().oSelectMarca.setModel(myModel);
var myvar = sap.ui.getCore().getModel("marcas");
var selectedKey= myvar.getProperty('/cards/Kunnr');
在selectedKey
中尝试双向数据绑定,这有助于保持MV*模式
var myvar = sap.ui.getCore().getModel("marcas");
var selectedKey= myvar.getProperty('/cards/Kunnr');
newselect({
selectedKey:“{/selectedCard}”//我通过使用sap core从外部访问属性解决了这个问题:
var myvar = sap.ui.getCore().getModel("marcas");
var selectedKey= myvar.getProperty('/cards/Kunnr');