2013-01-08 40 views
0

下面的代码通常会用尽堆栈空间,因为类型实体具有名为EntityAspect的属性,该属性具有指向拥有实体的实体类型实体类型的实体。这种递归定义会导致一些工具失败或运行非常缓慢,但最值得注意的是,淘汰赛。可以做什么来解决这个问题?微风实体类型具有递归定义

var custType = _this.metadataStore.getEntityType("Customer"); 
var cust1 = custType.createEntity(); 
var js = ko.toJS(cust1); 

回答

0

我还没有真正尝试过这个,但是我认为你可以做到这一点

var js = ko.mapping.toJS(cust1, { 
    ignore: ['entityAspect'] 
}); 
+0

忽略entityAspect可能不够 - 恐怕还有其他递归循环。我放弃了调用jS(),但将它作为调试场景中的一个选项会很好。 – pawel

+0

为了解决这个问题,我想在你使用toJS的时候,其他的东西会在封面上发生,因为它极其缓慢。我转而编写了一个定制的序列化程序,它的速度要快得多,但目前它很难看。当我清理它时,我会在GitHub上添加一个pull请求。 –

0

我发现我需要同时忽略entityAspect和的EntityType(来自自定义数据源数据源剑道片段):

  this.entityManager.executeQuery(query) 
      .then(function (xhr) { 
       if (self.autoMapToJS) { // Breeze entities contain recursive properties (ugh!) - eliminate those 
        payload.data = ko.mapping.toJS(xhr.results, { 
         ignore: ['entityAspect', 'entityType'] 
        }); 
       } else { 
        payload.data = xhr.results; 
       } 
       if (self.inlineCount) { 
        payload.total = xhr.inlineCount; 
       } 
       options.success(payload); // notify the DataSource that the operation is complete 
      }) 
      .fail(function (rejected) { 
       payload.error = rejected; 
      }) 
      .done(); // terminate chain of promises 
    } 

特别是,尝试使用网格(kendo),我被迫映射微风数据或享受stackoverflows,因为这些控件将迭代通过属性。

+0

也许你应该添加到你的ignore-list:“complexType”,“complexAspect”,“_ $ typeName”,“_ $ interceptor” – okieh