on 10-26-2015 10:43 PM
Hello Experts,
My challenge is to retrieve the Key value of a RBG in a Fiori app linked to an oData Service. From a Previous question I have obtained this answer: http://jsbin.com/hanadofuco/1/edit?js,output and it works fine in the json Model.
in my view.xml:
<RadioButtonGroup xmlns="sap.m"
id="Stoff"
Buttons="{/ZUI5_TEST_TVALUES_SET}"
width="500px"
class="sapUiMediumMarginBottom"
select="onSelectRadio">
<RadioButton text="{ATWTB}" key="{ATWRT}"/>
</RadioButtonGroup>
and the function in controller:
onSelectRadio: function(oEvent) {
var oSelectedIndex = oEvent.getParameter("selectedIndex");
var oModelo = this.getView().getModel();
var sKey = oModelo.getProperty("/ZUI5_TEST_TVALUES_SET/"+oSelectedIndex+"/ATWRT");
},
After getting the Model in "oModelo" (image from Debugger below), "Skey" still results in "undefined".
How can I obtain in this case the ATWRT value? (Key value) or this sap.m.RadioButtonGroup?
Thank you
PD I was able to retrieve the text value of a RBG (thanks to this post->) But now the question is about key value.
You can fetch the bindingContext from the instance of the selected item and get the data from the context.
onSelectRadio: function(oEvent) {
var oSource = oEvent.getSource();
var oContext = oSource.getSelectedButton().getBindingContext();
var oData = oContext..getObject();
console.log(oData.ATWRT);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you very much Sakthivel. Your solution works for obtaining the key value. I believe I understand now a little better the method "getBindingContext()" (I will take a look at the API at this point as you recommend).
@Karthik and @Dennis: your help is very appreciated I still learning from each of you.
Best Regards,
Gabriel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Karthik for correcting the initial JsBin. The question still remains: I wanted to try the same for a Fiori App that consumes Odata. The first step was to get the model:
"var oModel = this.getView().getModel();"
According to the debbuger, the model is obtained
The second step is to access the key of the radiobutton (I have not achieved that task). The Path is different from the one in the JsBin and I only obtain "undefined" Please see the first image I have included in the description.
I appreciate your help in advance,
Kind Regards,
Gabriel
Many Thanks Karthik for your answer. Perhaps I am not writing the collection name in the right way. In the screenshot of the debugger, I have highlighted in blue the path for each radiobutton.
I have tried writting the collection name:
- In this way -> "/ZUI5_TEST_TVALUES_SET/" ->
or rather this one? "/ZUI5_TEST_TVALUES_SET(ATNAM='FIORI_BEZUGSSTOFF',ATWRT='KL')"
I am obtaining from the debbuger the message: "Uncaught TypeError: Cannot read property 'getProperty' of null" in both cases.
I appreciate your support,
Kind Regards,
Gabriel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you very much Dennis for your reply. I have tried the "getSelectedButton" Method following your solution. I might be missing the best way to adapt it to my code. in the Detail.controller.js file I declare the function as follows:
onSelectRadio: function(oEvent) {
var btn = this.getSelectedButton();
var sKey = btn.getBindingContext().getObject().key);
alert(sKey);
The Chrome Debugger informs: "Uncaught TypeError: this.getSelectedButton is not a function" as in this screenshot:
Now the difference (I believe) is that in your jsBin the function is declared right away in the constructor. In my case, the function is in the controller and the RadioButtonGroup is created in the xml.view.
How could I implement your code in my case? Thank you in advance,
Gabriel
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.