当运行exportEntities时,breeze通过删除它们的属性并将它们弹出到数组中来实现展平实体。在仅具有简单属性的实体中,这会阻止循环引用,因为不会复制entityAspect。但是,复杂的属性不会被展平,并且仍然具有此entityAspect,当breeze尝试调用JSON.stringify()时会导致循环结构异常;
以下是一些复制此问题的代码:
var jsonMetadata = {
"metadataVersion": "1.0.3",
"dataServices": [
{
"serviceName": "api/Foo/",
"hasServerMetadata": false,
"jsonResultsAdapter": "webApi_default",
"useJsonp": false
}
],
"structuralTypes": [
{
"shortName": "address",
"namespace": "YourNamespace",
"isComplexType": true,
"dataProperties": [
{ "name": "street", "dataType": "String" },
{ "name": "city", "dataType": "String" },
{ "name": "country", "dataType": "String" }
]
},
{
"shortName": "person",
"namespace": "YourNamespace",
"dataProperties": [
{ "name": "id", "dataType": "Int32", isPartOfKey: true },
{ "name": "name", "dataType": "String" },
{ "name": "hobbies", "dataType": "String" },
{ "name": "address", "complexTypeName": "address:#YourNamespace" }
] }
]
};
var manager = new breeze.EntityManager();
manager.metadataStore.importMetadata(jsonMetadata)
var person = manager.createEntity('person', {id: 1});
person.address.street = "Sample Street";
console.log("Complex property is a circular datatype, cannot convert to JSON - that's fine")
// JSON.stringify(person.address); // fails with error
console.log("... except that manager.exportEntities() doesn't handle that case!");
manager.exportEntities(); // also fails
编辑:woops,糟糕的形式,遗漏了问题:这是一个错误吗?
答案 0 :(得分:1)
这是一个错误,已在Breeze v 1.3.5中修复,现在可通过nuget和Breeze网站获得。
和...好的复制品。我们很感激。