I have a Controller. In which I am defining data and setting it to a model. Later I want to bind this model's data to a List control in a view. Problem: But the problem is the data doesn't show up in the respective control to whom I am binding it. Can anyone help what I am doing wrong?
Here is my code for the controller and my view:
App.view.xml
<mvc:View xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:l="sap.ui.layout" xmlns:f="sap.ui.layout.form" xmlns:core="sap.ui.core"
displayBlock="true" controllerName="opensap.examples.controller.App" height="100%">
<Page title="List Page">
<content>
<List headerText="{/question}" id="myList" items="{ path: '/answers' }">
<items>
<InputListItem label="{answerText}">
<CheckBox></CheckBox>
</InputListItem>
</List>
<Button press="load" text="Click Me"></Button>
</content>
</Page></mvc:View>
App.controller.js
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/model/json/JSONModel"], function(Controller, JSONModel) {
var oData = {
"question": "Which pet do you like from the following?",
"answers": [{
"answerText": "Cats"
}, {
"answerText": "Rabbits"
}, {
"answerText": "Dogs"
}, {
"answerText": "Hamsters"
}]
};
var oModel;
Controller.extend("opensap.examples.controller.App", {
onInit: function() {
oModel = new JSONModel();
oModel.setData(oData);
console.log(oModel);
}, load: function() {
console.log(oModel);
}
}); });