如何读取多个记录的 OData 关联
How to read OData association for multiple records
让我们取 Northwind odata service as an example. To get all the products of a supplier '1' I would use the following URL,在 SAPUI5 中它等于:oModel.read("/Suppliers(1)/Products");
但是如果我有 10 个不同的供应商并且想要获得属于这些供应商的所有产品怎么办?正确的方法是什么?我应该在 oModel.read("/Suppliers(X)/Products");
循环,其中 X 是供应商编号吗?或者我应该在 Products 实体集上使用过滤器吗?
您可以过滤供应商并使用 $expand 查询属性将相应的产品包含到结果中。此 URL will return Suppliers with an ID less than 5 and their Products. As a Supplier might have a lot of products it may be better to do it the other way around, filter Products and expand the corresponding Supplier. This URL 将 return ID 和供应商 ID 小于 5 的产品。在实际场景中,您会应用不同的过滤器,但思路应该很清楚。
让我们取 Northwind odata service as an example. To get all the products of a supplier '1' I would use the following URL,在 SAPUI5 中它等于:oModel.read("/Suppliers(1)/Products");
但是如果我有 10 个不同的供应商并且想要获得属于这些供应商的所有产品怎么办?正确的方法是什么?我应该在 oModel.read("/Suppliers(X)/Products");
循环,其中 X 是供应商编号吗?或者我应该在 Products 实体集上使用过滤器吗?
您可以过滤供应商并使用 $expand 查询属性将相应的产品包含到结果中。此 URL will return Suppliers with an ID less than 5 and their Products. As a Supplier might have a lot of products it may be better to do it the other way around, filter Products and expand the corresponding Supplier. This URL 将 return ID 和供应商 ID 小于 5 的产品。在实际场景中,您会应用不同的过滤器,但思路应该很清楚。