如何使用SAPUI5在视图中嵌套模型绑定

时间:2016-08-30 20:03:21

标签: data-binding sapui5

数据模型:

[{
    "id": 51,
    "name": "BuildingA",
    "floors": [{
        "id": 101,
        "name": "UG"
    }, {
        "id": 102,
        "name": "EG"
    }, {
        "id": 103,
        "name": "1"
    }, {
        "id": 104,
        "name": "2"
    }, {
        "id": 105,
        "name": "3"
    }, {
        "id": 106,
        "name": "4"
    }]
}, {
    "id": 52,
    "name": "BuildingB",
    "floors": []
}]

控制器中的数据绑定:

this.getView().setModel(oResponseModel, "buildingNavigation");

视图中的数据绑定:

<tnt:NavigationList items="{path: 'buildingNavigation>/'}">
    <tnt:NavigationListItem text="{buildingNavigation>name}" icon="sap-icon://building" expanded="true" items="{path: 'buildingNavigation>floors', templateShareable:true}">
        <tnt:NavigationListItem text="{name}">
        </tnt:NavigationListItem>
    </tnt:NavigationListItem>
</tnt:NavigationList>

我正在使用here

中的NavigationList

基本上,绑定似乎有效,因为第一级填充了建筑物名称(例如BuildingA,BuildingB)。第二级似乎以检索正确数量的项目的方式工作。 (例如,建筑物A,有6x子级别,但我无法从楼层数组中接收属性名称。它只显示导航中的6个空条目。

我尝试了不同的组合: 例如/buildingNavigation>floors>name

模型中包含并接收所有相关信息。我似乎没有找到正确访问它的格式。

1 个答案:

答案 0 :(得分:2)

最内层NavigationListItem也会有模型的绑定别名。

您的代码将是:

<tnt:NavigationList items="{path: 'buildingNavigation>/'}">
    <tnt:NavigationListItem text="{buildingNavigation>name}" icon="sap-icon://building" expanded="true" items="{path: 'buildingNavigation>floors', templateShareable:true}">
        <tnt:NavigationListItem text="{buildingNavigation>name}">
        </tnt:NavigationListItem>
    </tnt:NavigationListItem>
</tnt:NavigationList>
相关问题