我正在尝试让 BreezeJS 库与 SAP OData 服务一起使用。这适用于读取实体,但我无法解析链接的对象。
我的 EntityType 是一个 OrgObject。
<EntityType Name="OrgObject" sap:content-version="1">
<!-- ... -->
<NavigationProperty Name="Children" Relationship="ZGW_ORGSTRUCTURE.OrgObject_To_Children" FromRole="FromRole_OrgObject_To_Children" ToRole="ToRole_OrgObject_To_Children"/>
</EntityType>
我有一个链接来解决所有链接的 OrgObjects(链接名为 Children)。
<Association Name="OrgObject_To_Children" sap:content-version="1">
<End Type="ZGW_ORGSTRUCTURE.OrgObject" Multiplicity="1" Role="FromRole_OrgObject_To_Children"/>
<End Type="ZGW_ORGSTRUCTURE.OrgObject" Multiplicity="*" Role="ToRole_OrgObject_To_Children"/>
</Association>
所以,这个微风查询正在工作:
var query = new breeze.EntityQuery().from("OrgObjects");
manager.executeQuery(query).then(function(data) {
data.results.forEach(function(item) {
console.log(item);
});
}).fail(/*...*/);
我如何从这个对象中调用“孩子”?
尝试1:
var query = new breeze.EntityQuery().from("OrgObjects");
manager.executeQuery(query).then(function(data) {
data.results.forEach(function(item) {
console.log(item);
// ...
var Children = item.Children();
// ...
});
}).fail(/*...*/);
这会导致错误:
message: "Object [object Object] has no method 'children'"
尝试2:
var query = new breeze.EntityQuery().from("OrgObjects");
manager.executeQuery(query).then(function(data) {
data.results.forEach(function(item) {
console.log(item);
// ...
item.entityAspect.loadNavigationProperty("Children").then(function(data) {
console.log(data.results);
data.results.forEach(function(item) {
console.log(item);
});
}).fail(function(e) {
console.log(e);
});
// ...
});
}).fail(/*...*/);
这会导致错误:
“propertyOrExpr”参数必须是“字符串”
尝试 3:
var query = new breeze.EntityQuery().from("OrgObjects").expand("Children");
manager.executeQuery(query).then(function(data) {
data.results.forEach(function(item) {
console.log(item);
// ...
console.log(item.Children);
console.log( item.Children.length );
// ...
});
}).fail(/*...*/);
结果: item.Children
是一个对象。但是item.Children.length = 0
。item.Children
当我检查 http 响应时,子项是从服务器获取的,但在对象中不可用。
控制台输出:
Finance Department
[parentEntity: Object, navigationProperty: ctor, arrayChanged: ctor, _addsInProcess: Array[0], push: function…]
_addsInProcess: Array[0]
_getEventParent: function () {
_getPendingPubs: function () {
arrayChanged: ctor
length: 0
load: function (callback, errorCallback) {
navigationProperty: ctor
parentEntity: Object
pop: function () {
push: function () {
shift: function () {
splice: function () {
unshift: function () {
__proto__: Array[0]
0
谁能帮帮我?我的 OData 服务中是否缺少某些内容?