以下代码通常会耗尽堆栈空间,因为类型Entity具有名为EntityAspect的属性,该属性具有一个名为Entity的属性Entity,该属性指向拥有的Entity。这种递归定义导致几个工具失败或运行速度极慢,但最值得注意的是,淘汰赛。可以做些什么来解决这个问题吗?
var custType = _this.metadataStore.getEntityType("Customer");
var cust1 = custType.createEntity();
var js = ko.toJS(cust1);
答案 0 :(得分:0)
我还没有尝试过,但我认为你可以做到这一点
var js = ko.mapping.toJS(cust1, {
ignore: ['entityAspect']
});
答案 1 :(得分:0)
我发现我需要忽略entityAspect和entityType(来自自定义数据源kendo数据源的片段):
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
}
特别是,尝试使用网格(wijmo& kendo)时,我被迫映射breeze数据或享受stackoverflows,因为这些控件将遍历属性。