最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to retrieve a field value on SAPUI5 - Stack Overflow

programmeradmin1浏览0评论

I'm starting on OPENUI5/SAPUI5 and I was trying to access the data for the controls i've implemented. For example:

<Label text="Amount" /> <Input id="inputAmount" value="{Amount}" /> <Text id="lblCurrency" text="USD" >

  1. How to get the programatically values for inputAmount or lblCurrency?
  2. Initially i'm using a mockup-server, how to get access to the odata model programatically? I'm using:

console.log( this.getView().getModel().getJSON() );

I can't get the structure, but i had deployed the data on the objects and actually is showed on screen.

I'm starting on OPENUI5/SAPUI5 and I was trying to access the data for the controls i've implemented. For example:

<Label text="Amount" /> <Input id="inputAmount" value="{Amount}" /> <Text id="lblCurrency" text="USD" >

  1. How to get the programatically values for inputAmount or lblCurrency?
  2. Initially i'm using a mockup-server, how to get access to the odata model programatically? I'm using:

console.log( this.getView().getModel().getJSON() );

I can't get the structure, but i had deployed the data on the objects and actually is showed on screen.

Share Improve this question asked Aug 1, 2016 at 21:10 MarioMario 752 gold badges2 silver badges6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 2

you can get the control by it's id and then access it's value so in your code:

Accessing the Text control in the controller

sap.ui.getCore().byId("lblCurrency").getText() 

Accessing the Input value control in the controller

sap.ui.getCore().byId("inputAmount").getValue()

The code above show how to access to value in the standard way. If you will use binding (binding is when you have a model which updates your view and if it's 2-way binding also your view updates you model) then in order to access to value you need to access access the model and extract it from there

example of binding and how to use it can be found here:

https://help.sap./saphelp_uiaddon10/helpdata/en/91/f0f3cd6f4d1014b6dd926db0e91070/content.htm

Update

in order to get the data from the model you need to use the getProperty function under the model so your code should look some

oModel.getProperty("{PATH_TO_WHERE_THE_PROPERTY_IS_LOCATED",{OPTIONAL_CONTEXT}};
发布评论

评论列表(0)

  1. 暂无评论