问题
I want to use only XML to bind a list to the data of a JSON file.
Here is my code:
XML View:
<List
headerText="Positions"
items="{/Positions}">
<ObjectListItem
title="{positions>id}">
</ObjectListItem>
</List>
index.html
var oPositionsModel = new sap.ui.model.json.JSONModel();
oPositionsModel.loadData("model/Positions.json");
sap.ui.getCore().setModel(oPositionsModel);
model/Positions.json
{
"Positions": [
{
"id": 123456,
"article": "Abcde",
"amount": 12
},
{
"id": 654321,
"article": "Edcba",
"amount": 21
}
]
}
I can't see, what's wrong. But I get "no data" all the time. There is nothing in the console saying there is a problem here.
回答1:
Your binding for the title
attribute is not correct. You want to bind it directly to the id
attribute of Positions
, no need to specify the model:
<List
headerText="Positions"
items="{/Positions}">
<ObjectListItem
title="{id}">
</ObjectListItem>
</List>
Working demo in JSBin
来源:https://stackoverflow.com/questions/38075526/binding-in-list-with-xml