運行exportEntities時,breeze通過刪除它們的屬性並將它們彈入數組來實現扁平化實體。在僅具有簡單屬性的實體中,由於不會複製entityAspect,因此可防止循環引用。然而,複雜的屬性並不平坦,仍然有這個entityAspect,當breeze試圖調用JSON.stringify()時導致一個循環結構異常。Breeze.js - 複雜屬性在em.exportEvent中導致循環結構異常
下面是一些代碼複製此問題:
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,表現欠佳,留出了一個問題:這是一個錯誤?
你的問題是什麼? –
好repro .. thx,我現在看它,並會在我有答案時重新發布。 –