Skip to Content

add content simpleform dynamically

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Oct 12, 2016 at 05:04 PM

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

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

    Regards,

    Jamie

    SAP - Technology RIG

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 13, 2016 at 08:40 AM
    -1

    Yes, Jamie is correct.

    Add comment
    10|10000 characters needed characters exceeded