我有以下 D3 代码,它按预期工作。树已渲染,并且可以在单击节点时展开和折叠。
`` http://jsfiddle.net/6Ldad16n/3/
现在,我需要从 Ext JS 代码中运行它。所以我为此创建了另一个 fiddle
`` http://jsfiddle.net/07kk8fzs/2/
在 Ext JS 版本中,我无法折叠树。折叠需要从更新函数内部调用更新函数,这会产生错误
this.update(d);
-
Uncaught TypeError: this.update is not a function
有人可以帮助我理解为什么会发生这种情况以及如何解决这个问题。
谢谢
最佳答案
您需要将范围存储在构造函数的属性中,然后使用它在更新函数中调用“更新”。这是你的 fiddle 修复:http://jsfiddle.net/kqr57ad3/
Ext.define("d3.widgets.Treeview", {
extend: 'Ext.Panel',
alias: 'widget.d3_treeview',
tree: '',
svg: '',
duration: 1000,
diagonal: '',
i: 0,
me: null,
constructor: function (config) {
console.log('1) Tree View Constructor called');
this.callParent([config]);
console.log("Treeview - constructor FINISH");
me = this;
},
然后在更新函数中使用此引用:
me.update(d);
关于javascript - 在 Ext JS 4.2 中创建 D3 可折叠树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30212558/