on 04-29-2016 11:26 AM
Hi Gurus,
I bound the items with a entity set in my OData, but now here comes the question, i.e. how could I get the use selected key or value?
Here is the select/dropdown box snapshot.
And here is the code snippet snapshot.
The content in BPRoleModel>/d/results, as what is seen in the last snap pic, has been populated in the select/dropdown box successfully via this in controller.
The value BPGroup is a field name in an entity.
How could I get the key value and put it into the field BPGroup?
Try the below:
this.getView().byId('BPGroupSelect').getSelectedKey(); // get selected item's key
this.getView().byId('BPGroupSelect').getLiveValue(); // get selected item's value
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You will have to call the create/update function on the entity which holds the BPGroup field in your service.
You can refer to the below links which show the method signatures of these 2 functions:
SAPUI5 SDK - Demo Kit - create
SAPUI5 SDK - Demo Kit - update
Regards,
Saurabh
Hi Saurabh,
Thank you for your reply.
As what you've said, if I want to implement some logic with the value of BPGroup, I do need to 'call the create/update function on the entity which holds the BPGroup field in your service.'.
But the thing is, how could I get the key value selected by a user put into the field BPGroup so that the back end can do something with it?
I kindly suggest you to go thru the whole question again.
Regards,
Xuebin
I'm still not clear what your confusion is. There are 2 parts here: first, getting the selected value from the sap.m.Select and maybe storing it in a JavaScript object; then passing on the object along with the selected value to the OData service using the create/update method. Second - getting this value in the OData service's create/update method and updating this to the relevant back end tables. Are you not clear on the front end part (in your SAPUI5 application) or the back end part(OData service)?
Hi Saurabh,
Let me make myself much clearer.
If I wanner get the value/key selected by a user in a sap.m.Select( or a dropdown box ), and the values listed inside it is from back-end, i.e. OData service, I think 3 steps are mandatory:
1. Prepare values/keys and get them shown in sap.m.Select(or a dropdown box);
E.g.
Key Value
1 Male
2 Female
( I've done successfully. )
2. Pass the value/key a user selected to a entity field, i.e. BPGroup here in the snapshot;
E.g.
The user select Male, and it is passed to BPGroup.
(That's what I am wondering.)
3. As what you've mentioned, do something with the value in BPGroup in back-end, i.e. getting this value in the OData service's create/update method and updating this to the relevant back end tables.
E.g.
Find the Male a pretty girlfriend if he isn't coming out of the closet.
( I can say for sure that I can do this because I've done this with other input fields. )
Hope this is clear.
Regards,
Xuebin
In that case you will have to fetch the value selected by the user in the dropdown using the below code and save it in a JavaScript object:
var selectedVal = this.getView().byId('BPGroupSelect').getLiveValue(); // get selected item's value
var aData = {"BPGrp": selectedVal, "name1":....., "name2":..... etc};
Then assuming you are updating the details in the back end from the OData service, create ODataModel and call its update method as shown below:
var oModel = new sap.ui.model.odata.ODataModel("<serviceURL>");
oModel.update("/Account('12345')", aData, null, function(oData) {alert("data updated");}, function(oError) {alert("error occurred while updating data");});
Hi Saurabh,
Your reply looks like a nice way to get this done.
Could you make it more detailed on 'save it in a JavaScript object'?
var aData = {"BPGrp": selectedVal, "name1":....., "name2":..... etc};
var selectedVal = this.getView().byId('BPGroupSelect').getLiveValue(); // get selected item's value
var aData = {"BPGrp": selectedVal, "name1":....., "name2":..... etc};
How could I put the selected key/value into a JSON model?
Regards,
Xuebin
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
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.