在我的Angular应用程序中,我使用$ odataresource指令以下列方式使用OData v4 feed:
http://10.0.0.4:8080/InformationProduct?$expand=DataEntities($expand=DataSources)
此查询在Fiddler,Postman以及任何现代浏览器中运行良好:
{
@odata.context: "http://10.0.0.4:8080/$metadata#InformationProduct",
value: [{
ID: 1,
Name: "ODM Dashboard",
Description: "ODM Dashboard",
Governance_ID: 1,
PerformanceMetric_ID: 1,
DataEntities: [{
ID: 1,
Name: "Data Entity 1",
Description: "Data Entity 1",
InformationProduct_ID: 1,
BiMeasure_ID: null,
BiFact_ID: null,
BiDimension_ID: 1,
DataSources: [{
ID: 40,
Category: "Service Performance",
SourceSystemName: "Account Improvement Plan",
SourceSystemOwner: null,
SourceSystemLocation: null,
SourceSystemTeam: null,
SourceSystemNetworkSegment: null,
SourceSystemOsType: null,
SourceDatabaseName: null,
SourceDatabaseType: null,
SourceDatabaseVersion: null,
BiFact_ID: null
}]
}]
}]
}
我正在尝试在我的Angular控制器中实现相同的查询,如下所示:
function getData(){
$odataresource("http://windows-10:8080/InformationProduct")
.odata()
.expand('SourceTools')
.expand('DataEntities','DataSources')
{}
}
我收到了这个错误:
GET http://windows-10:8080/InformationProduct?$expand=SourceTools,DataEntities/DataSources 400 (Bad Request)
很明显,$ odataresource不会翻译.expand('DataEntities','DataSources')
进入$expand=DataEntities($expand=DataSources)
让$ odataresource指令产生这样的嵌套$ expand的正确方法是什么?
答案 0 :(得分:1)
docs状态,您需要使用isodatav4属性让它知道您正在使用v4端点:
要启用此行为,请将isodatav4属性设置为true 调用$ odataresource方法:
User = $odataresource('/user', {}, {}, {
odatakey: 'id',
isodatav4: true
});
然后使用这样的expand方法:
var result = User.odata().expand("roles", "role").query();
// /user?$expand=roles($expand=role)
对您而言,这意味着您已拥有正确的展开式通话,只需将isodatav4
标记添加到$odataresource("http://windows-10:8080/InformationProduct")
即可$odataresource("http://windows-10:8080/InformationProduct", {}, {}, { isodatav4: true })