我正在尝试绑定SAPUI5应用程序中嵌套JSON文件的数据。该视图采用XML格式。
以下是我的JSON文件中的代码段:
{
"Departments": [
{
"ID": "1",
"Name": "Транспортный цех 1",
"Count": 35,
"Address": "Корпус 1, Этаж 7",
"Logo": "image/manager1.jpg",
"Employees": [
{
"ID": "1000001234",
"LastName": "Базенков",
"FirstName": "Андрей",
"MiddleName": "Анатольевич"
},
{
"ID": "1000001234",
"LastName": "Базенков",
"FirstName": "Андрей",
"MiddleName": "Анатольевич"
}
]
},
{
"ID": "2",
"Name": "Транспортный цех 2",
"Count": 35,
"Address": "Корпус 1, Этаж 7",
"Logo": "image/manager1.jpg",
"Employees": [
{
"ID": "1000001234",
"LastName": "Базенков",
"FirstName": "Андрей",
"MiddleName": "Анатольевич"
},
{
"ID": "1000001234",
"LastName": "Базенков",
"FirstName": "Андрей",
"MiddleName": "Анатольевич"
}
]
}
]
}
我正在我的控制器中加载JSON文件,然后绑定数据"地址"和"姓名"在我的XML视图中如下:
<List id="list1" items="{path:'/Departments'}">
<items>
<ObjectListItem icon="{Logo}" type="Active" press="onListItemPress" number="{Count}" title="{Name}">
<attributes>
<ObjectAttribute text="{Address}" />
</attributes>
</ObjectListItem>
</items>
</List>
然而,当我尝试绑定嵌套数据&#34; FirstName&#34;或&#34;姓氏&#34;像这样我无法绑定它。
text="{Employees/LastName}"
答案 0 :(得分:2)
员工是一个阵列。
如果您愿意,可以选择一个条目并使用{Employees/0/LastName}
。
您还可以使用格式化程序功能将员工合并为字符串:
查看:
<ObjectAttribute text="{path: 'Employees', formatter: '.formatEmployees'}"/>
控制器:
formatEmployees: function(aEmployees){
return aEmployees.map(function(employee){ return employee.LastName + ", " + employee.FirstName; }).join("; ");
}