我使用Breeze Edmunds作为例子。
如下所示,我在Make实体上添加了一个新的名称数据属性作为复杂类型。复杂类型显示在初始化函数的底部。
在调用web api并返回结果后,我在make结果中看到了新的data属性,但是没有这个新名称的数据。如下所示:
Array[61]
0: proto._setCtor.proto
_backingStore: Object
entityAspect: ctor
id: (...)
modelLinks: (...)
models: (...)
name: "AM General"
**names**: proto._setCtor.proto
_backingStore: Object
complexAspect: ctor
name: ""
__proto__: Object
niceName: (...)
__proto__: Object
1: proto._setCtor.proto
2: proto._setCtor.proto
3: proto._setCtor.proto
4: proto._setCtor.proto
5: proto._setCtor.proto
6: proto._setCtor.proto
7: proto._setCtor.proto
8: proto._setCtor.proto
9: proto._setCtor.proto
10: proto._setCtor.proto
11: proto._setCtor.proto
12: proto._setCtor.proto
13: proto._setCtor.proto
14: proto._setCtor.proto
15: proto._setCtor.proto
16: proto._setCtor.proto
17: proto._setCtor.proto
18: proto._setCtor.proto
19: proto._setCtor.proto
20: proto._setCtor.proto
21: proto._setCtor.proto
22: proto._setCtor.proto
23: proto._setCtor.proto
24: proto._setCtor.proto
25: proto._setCtor.proto
26: proto._setCtor.proto
27: proto._setCtor.proto
28: proto._setCtor.proto
29: proto._setCtor.proto
30: proto._setCtor.proto
31: proto._setCtor.proto
32: proto._setCtor.proto
33: proto._setCtor.proto
34: proto._setCtor.proto
35: proto._setCtor.proto
36: proto._setCtor.proto
37: proto._setCtor.proto
38: proto._setCtor.proto
39: proto._setCtor.proto
40: proto._setCtor.proto
41: proto._setCtor.proto
42: proto._setCtor.proto
43: proto._setCtor.proto
44: proto._setCtor.proto
45: proto._setCtor.proto
46: proto._setCtor.proto
47: proto._setCtor.proto
48: proto._setCtor.proto
49: proto._setCtor.proto
50: proto._setCtor.proto
51: proto._setCtor.proto
52: proto._setCtor.proto
53: proto._setCtor.proto
54: proto._setCtor.proto
55: proto._setCtor.proto
56: proto._setCtor.proto
57: proto._setCtor.proto
58: proto._setCtor.proto
59: proto._setCtor.proto
60: proto._setCtor.proto
length: 61
__proto__: Array[0]
我缺少什么?
...谢谢
metadataStore.addEntityType({
shortName: "Make",
namespace: "Edmunds",
dataProperties: {
id: { dataType: DT.Int64, isPartOfKey: true },
name: { dataType: DT.String },
names: { dataType: DT.ComplexType, complexTypeName: "Names:#Edmunds", isScalar: true },
niceName: { dataType: DT.String },
modelLinks: { dataType: DT.Undefined }
},
navigationProperties: {
models: {
entityTypeName: "Model:#Edmunds", isScalar: false,
associationName: "Make_Models"
}
}
});
metadataStore.addEntityType({
shortName: "Names",
namespace: "Edmunds",
isComplexType: true,
dataProperties: {
name: { dataType: DT.String, isNullable: false }
}
});
答案 0 :(得分:0)
如果您更改此示例中的元数据,则需要更改' jsonResultsAdapter'代码也是如此。
答案 1 :(得分:0)
I added the complex type as well as the undefined type and as you can there is no data resturned in the complexy type but the undefined type returned fine.
Model Changes
function initialize(metadataStore) {
metadataStore.addEntityType({
shortName: "Make",
namespace: "Edmunds",
dataProperties: {
id: { dataType: DT.Int64, isPartOfKey: true },
modelList: { dataType: DT.ComplexType, complexTypeName: "ModelList:#Edmunds", isScalar: true },
name: { dataType: DT.String },
niceName: { dataType: DT.String },
modelLinks: { dataType: DT.Undefined }
}
//navigationProperties: {
// models: {
// entityTypeName: "Model:#Edmunds", isScalar: false,
// associationName: "Make_Models"
// }
//}
});
This is my jsonResultsAdapter code
visitNode: function (node, parseContext, nodeContext) {
// Make parser
if (node.id && node.models) {
// move 'node.models' links so 'models' can be empty array
modelList = node.models;
node.modelLinks = node.models;
//node.models = [];
return { entityType: "Make" }
}
// Model parser
else if (node.id && node.makeId) {
// move 'node.make' link so 'make' can be null reference
node.makeLink = node.make;
node.make = null;
// flatten styles and sizes as comma-separated strings
var styles = node.categories && node.categories["Vehicle Style"];
node.vehicleStyles = styles && styles.join(", ");
var sizes = node.categories && node.categories["Vehicle Size"];
node.vehicleSizes = sizes && sizes.join(", ");
return { entityType: "Model" };
}
This is the results
未定义类型显示数组[1]的数据,而复杂类型显示数据具有空值,并且是proto._setCtor.proto
This is the JSON
{" makeHolder":[{" ID":200347864"模式":[{"连结":" / API /载体/ AM-一般/悍马"" ID":" AM_General_Hummer""名称":"悍马"} ],"名称":" AM General"," niceName":" amgeneral"," manufacturer":null, " attributeGroups":{}}]}