I have encountered a problem with data visualization when using the XML view compared to the JSON view in a simple example. The binding works fine with JSON, but no data is visualized with XML. Why is that?
This code snippet represents the controller logic for both XML and JSON views..
sap.ui.controller("appIntra.test", {
onInit : function() {
var data = {
names: [
{firstName: "Peter", lastName: "Mueller"},
{firstName: "Petra", lastName: "Maier"},
{firstName: "Thomas", lastName: "Smith"},
{firstName: "John", lastName: "Williams"},
{firstName: "Maria", lastName: "Jones"}
]
};
// create a Model with this data
var model = new sap.ui.model.json.JSONModel();
model.setData(data);
console.log("controller");
sap.ui.getCore().setModel(model);
//this.getView().setModel(model);
},
});
Now let's take a look at the JSON view.
sap.ui.jsview("appIntra.test", {
/** Specifies the Controller belonging to this View.
* In the case that it is not implemented, or that "null" is returned, this View does not have a Controller.
* @memberOf appIntra.test
*/
getControllerName : function() {
return "appIntra.test";
},
/** Is initially called once after the Controller has been instantiated. It is the place where the UI is constructed.
* Since the Controller is given to this method, its event handlers can be attached right away.
* @memberOf appIntra.test
*/
createContent : function(oController) {
console.log("view");
// create a List control
var list = new sap.m.List({
headerText:"Names"
});
// bind the List items to the data collection
list.bindItems({
path : "/names",
template : new sap.m.StandardListItem({
title: "{lastName}",
description: "{firstName}",
type: sap.m.ListType.Navigation,
})
});
return new sap.m.Page({
title: "Title",
content: list
});
}
});
Lastly, here is a snippet of the XML view.
<List
items="{
path: '/items',
sorter: {
path: 'padre',
descending: false,
group: true
}
}"
headerText="Operazioni" >
<StandardListItem
title="{text}"
/>
</List>