on 03-14-2021 12:50 AM
Hello,
I would like to get the values of the inputs of the view file from Component.js.
I was able to get the view file inputs from Controller.js as shown in the image below, but I don't know how to get them from Component.js.
View file:
Controller.js:
I would appreciate it if you could tell me how I can link Component.js to a View file and retrieve the data.
Sincerely,
Kai Umeki
It would be easier for you to use binding here, try using JSON model binding then bind it's property to the input field. Later you can access that binding data in any other view or in component easily.
https://ui5.sap.com/#/topic/d70e9894c09b4c27a98d4850d4e90f2c
https://ui5.sap.com/#/topic/91f0652b6f4d1014b6dd926db0e91070
Then you can use this.getModel("testmodel").getData(); // you will have your model data here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData({"field1":"","field2":""})
this.setModel(oModel,"testModel")
Now, in the view, use that<Text text="{/field1}" />
Now in the component, access itthis.getModel("testModel").getData(); // {field1:"",field2:""}
hi ,
var data=this.getModel("modelname").getData() will return array of data so to access a particular property value you need to specify the
// var propertyValue=data[index].propertyName;
or
alert(data[index].propertyName)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
put a debug point at line of alert(***), check data1 in dev tool , you will get better idea.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Mahesh Kumar Palavalli,
Thank you very much for your replying and advises.
I wrote the code as you taught me, as follows.
Component.js's define section is shown in the figure below.
And the model creation, assignment, and data acquisition parts of component.js are shown below.
I tried to check the contents of the variables retrieved using the alert.
And here is the text part to get.
And here is the result of the execution. I can confirm that I was only able to get the value as an object and not the actual value.
I do not understand why this is happening. If you could please advise me on this, I would appreciate it.
Thank you very much for your advice again and again.
I really appreciate it.
Regards,
Kai Umeki
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you need to know how to access an object in javascript. For this reason I recommended you to do the basics first which will help u to solve this simple issues.
for eg. "{"test":1} -> this is an object/map data in javascript, google about it and learn how to access it.. To access the data, u need to use data1.field1
great to hear that kaiumeki.
I still suggest you to brush up your skills in javascript and HTML(a bit), you will love it for sure.
All the best
Mahesh
User | Count |
---|---|
76 | |
9 | |
7 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.