Binding in List with XML

房东的猫 提交于 2019-12-25 07:59:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!