我创建了一个 fiori 应用程序并尝试使用控制器中的 odata 读取功能获取数据。在视图中访问数据的正确方法是什么。 工作正常的后端请求:/sap/opu/odata/sap/ZodatSRV/empSalesSet?$expand=set1,set2,set3,set4,set5&$filter=(category eq 'empSales')
查看不起作用的代码:
<Text text="{/category}"></Text>
<Text text="{empSalesSet/category}"></Text>
<Text text="{category}"></Text>
从结果集中访问数据的正确方法是什么?我需要对视图进行任何特定的绑定吗?请让我知道我错过了什么。
控制器代码:
onInit: function () {
var oDataModel = this.getView().getModel();
var aFilter = [];
var oFilter = {};
oFilter = new Filter("category", FilterOperator.EQ, "empSales");
aFilter = [oFilter];
oDataModel.read("/empSalesSet", {
urlParameters: {
"$expand": "set1,set2,set3,set4,set5"
},
filters: aFilter,
success: function (data, response) {},
error: function (oError) {}
});
}
在 Chrome 控制台中,我可以看到数据以 json 格式作为嵌套数组出现
{
"d": {
"results": [{
"__metadata": {
"id": "",
"uri": "",
"type": "Znn"
},
"category": "empSales",
"set1": {
"results": []
},
"set2": {
"__metadata": {
"id": "",
"uri": "",
"type": "XXXXX"
},
"category": "todayTotal",
"salesTotal": "",
"marketingLineUpBestTotal": ""
},
"set3": {
"results": [{
"__metadata": {
"id": "vv",
"uri": "bb",
"type": "nn"
},
"category": "mtd",
"employeeName": "A Marc",
"sales": "1203.23",
"marketingLineUpBest": "5.000"
}, {
"__metadata": {
"id": "",
"uri": "",
"type": ""
},
"category": "cat",
"employeeName": "MUL2ECCDEV",
"sales": "0",
"marketingLine": "1"
}]
},
"set4": {
"__metadata": {
"id": "",
"uri": "",
"type": ""
},
"salesTotal": "1203.23",
"totalUnitsTotal": "5.000",
"usedUnitsTotal": "0",
"marketingLineUpBestTotal": "5.000"
},
"set5": {
"__metadata": {
"id": "",
"uri": "",
"type": ""
},
"category": "site",
"site": "1002",
"siteName": "106",
"empSales": {
"__deferred": {
"uri": ""
}
}
}
}]
}
}
在 xml 视图中应该使用什么语法来显示来自集合 3 数组的数据,集合 4