Having this select control:
new Select("id", {
items: {
path: "/cards",
template: new ListItem({
key: "{Kunnr}",
text: "{Descrip}"
}),
},
});
I need it be able to get the selected key of it, but not in the change event. I need it from outside (another function).
I have tried using the ID but I just get undefined
as result.
Try with two-way data binding in
selectedKey
which helps to keep the MV* pattern.I'm assuming that the default model is accessible across the application. Hence, as long as you can access that model, you can get the selected key by
myModel.getProperty("/selectedCard");
I solved it by accesing to the properties from outside using the sap core:
There is a some information missing from your question, mostly around how
oSelectMarca
is added to your view. This makes a difference in how it's made available in your app. There are two places to get something by Id:You'll have to check which one it is... Another option is to add that model to your view instead of
oSelectMarca
in which case your view and your select can share data. But once again that depends on how you add the select to the screen.Depending on where You need to use it You can do:
or If You'll be using it in say another controller try: