2

运行 exportEntities 时,微风通过删除它们的属性并将它们弹出到数组中来使实体变平。在只有简单属性的实体中,这可以防止循环引用,因为 entityAspect 不会被复制。但是复杂的属性没有展平,仍然有这个entityAspect,导致微风尝试调用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

编辑:哎呀,糟糕的形式,遗漏了这个问题:这是一个错误吗?

4

1 回答 1

1

这是一个错误,已在 Breeze v 1.3.5 中修复,现在可通过 nuget 和 Breeze 网站获得。

和......很好的复制品。我们很感激。

于 2013-06-04T21:38:12.403 回答