Skip to Content
0

add content simpleform dynamically

Oct 12, 2016 at 09:42 AM

82

avatar image

Hi

Here is my code:

var ipData = [ { flname: "Test ID"},{ flname: "To Date"}];

var oSimpleForm = new sap.ui.layout.form.SimpleForm( { layout: sap.ui.layout.form.SimpleFormLayout.ResponsiveGridLayout,

content:[ new sap.ui.core.Title({text:""}),

new sap.ui.commons.Label({text:"ID"}),

new sap.ui.commons.TextField({value:" test"}),

.......

var ipmodel = new sap.ui.model.json.JSONModel();

ipmodel.setData(ipData);

var len = ipmodel.oData.length;

for(i=0;i<=len;i++) {

oSimpleForm.addContent(new sap.ui.commons.Label({ text: ipmodel.oData[i].flname }) ); oSimpleForm.addContent(new sap.ui.commons.TextField({value:ipmodel.oData[i].flname})); }

In structure ipData I have flname but above code gives error that "Cannot read property 'flname' of undefined" whereas the data is correctly defined inside model and I verified by printing in console as well.

The control runs well if I replace text to something static or index i. Please let me know what is wrong with above code.

10 |10000 characters needed characters left characters exceeded

Hi Justin, can you please format your code?

Also you should attach a dump of your current JSON inside ipData

0
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Jamie Cawley
Oct 12, 2016 at 05:04 PM
3

Your loop is going passed the bounds of your array. It should be

for(i=0;i<len;i++) {

Regards,

Jamie

SAP - Technology RIG

Share
10 |10000 characters needed characters left characters exceeded
Akhilesh Upadhyay Oct 13, 2016 at 08:40 AM
-1

Yes, Jamie is correct.

Share
10 |10000 characters needed characters left characters exceeded