breeze实体类型具有递归定义
以下代码通常会耗尽堆栈空间,因为类型实体有一个名为EntityAspect的属性,该属性有一个名为Entity的属性,该属性指向所属实体的类型Entity。这种递归定义会导致一些工具失败或运行速度非常慢,但最显著的是击倒。有什么办法可以解决这个问题吗breeze实体类型具有递归定义,breeze,Breeze,以下代码通常会耗尽堆栈空间,因为类型实体有一个名为EntityAspect的属性,该属性有一个名为Entity的属性,该属性指向所属实体的类型Entity。这种递归定义会导致一些工具失败或运行速度非常慢,但最显著的是击倒。有什么办法可以解决这个问题吗 var custType = _this.metadataStore.getEntityType("Customer"); var cust1 = custType.createEntity(); var js = ko.toJS(cust1);
var custType = _this.metadataStore.getEntityType("Customer");
var cust1 = custType.createEntity();
var js = ko.toJS(cust1);
我还没有试过,但我想你可以做到
var js = ko.mapping.toJS(cust1, {
ignore: ['entityAspect']
});
我发现我需要同时忽略entityAspect和entityType(来自自定义数据源kendo数据源的片段):
特别是,试图使用网格(wijmo和kendo),我被迫映射breeze数据或享受stackoverflows,因为这些控件将遍历属性 忽略entityAspect可能不够-恐怕还有其他递归循环。我放弃了调用toJS(),但在调试场景中将其作为一个选项会很好。为了解决这个问题,我认为在使用toJS时,会有一些其他的事情隐藏起来,因为它非常慢。我切换并编写了一个定制的序列化程序,速度要快得多,但目前还很难看。当我清理它时,我将在GitHub上执行一个pull请求来添加它。也许你应该添加到忽略列表中:“complexType”、“ComplexSpect”、“_$typeName”、“_$interceptor”
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
}