sapui5复杂的数据绑定

时间:2016-05-28 08:01:31

标签: javascript data-binding sapui5

我有以下JSON模型:

{
    "Auctions": [{
        "AuctionsTypes": [{
            "AuctionType": "Contract",
            "Auctions": [{
                "AuctionID": "12345"
            }, {
                "AuctionID": "54321"
            }]
        },{
            "AuctionType": "Delivery",
            "Auctions": [{
                "AuctionID": "12345"
            }, {
                "AuctionID": "54321"
            }]
        }]
    }]
}

我的JS:

var oAuctionsModel = new sap.ui.model.json.JSONModel();
oAuctionsModel.loadData("model/mock_auction_types.json");
oView.setModel(oAuctionsModel, "auctions");

我想在列表中输出AuctionsType,但此代码不起作用。列表是空的。

<List id="idListAuctions" items="{auctions>/Auctions/AuctionsTypes}">
  <items>
    <StandardListItem title="{auctions>AuctionType}" type="Navigation" press="doSomething" />
  </items>
</List>

1 个答案:

答案 0 :(得分:1)

在您的数据中,Auctions本身就是一个数组,因此您必须指定要访问的内部数组元素。

在你的例子中,第一个:

<List items="{auctions>/Auctions/0/AuctionsTypes}">
    <StandardListItem title="{auctions>AuctionType}" />
</List>