0
votes

I am trying to bind data from controller to view but for some reason I am unable to display data in the view. I am setting the model using the following code:

var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(oObject);
this.getView().setModel(oModel);
console.log("DATA:-->"+ JSON.stringify(this.getView().getModel().getData()));

The console statement prints the data properly but in the view the data is not appearing. Am I missing something. I am unable to find the problem.

My View:

.....
<form:SimpleForm
    id="iform"
    minWidth="1024"
    maxContainerCols="2" >
    <Label text="Name"/>
    <Text text="{NAME}"/>
    <Label text="Age"/>
    <Text text="{AGE}"/>
</form:SimpleForm>
.....

Thanks in advance.

1
what does your JSON look like? - Haojie
It looks like this : [{"NAME":"Ajay","AGE":"35"}] - Zee
You are using an array of objects, so you should bind it accordingly : <Text text="{/0/NAME}" /> etc - Qualiture
@Qualiture.. I didnot know that. Thanks! Working great! - Zee

1 Answers

2
votes

Binding path should be {/0/Name} and {/0/AGE}

<form:SimpleForm
    id="iform"
    minWidth="1024"
    maxContainerCols="2" >
    <Label text="Name"/>
    <Text text="{/0/NAME}"/>
    <Label text="Age"/>
    <Text text="{/0/AGE}"/>
</form:SimpleForm>