在 Ext JS 4.2 中创建 D3 可折叠树
Creating D3 collapsible tree within Ext JS 4.2
我有以下 D3 代码,它按预期工作。树已呈现,可以在单击节点时展开和折叠。
``http://jsfiddle.net/6Ldad16n/3/
现在,我需要从 Ext JS 代码中 运行 这个。所以我为此
创建了另一个 fiddle
``http://jsfiddle.net/07kk8fzs/2/
在 Ext JS 版本中,我无法折叠树。折叠需要在update函数内部调用update函数,报错
this.update(d);
-
Uncaught TypeError: this.update is not a function
谁能帮我理解为什么会这样以及如何解决这个问题。
谢谢
您需要将范围存储在构造函数的 属性 中,然后使用它在更新函数中调用 "update"。这是您的 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);
我有以下 D3 代码,它按预期工作。树已呈现,可以在单击节点时展开和折叠。
``http://jsfiddle.net/6Ldad16n/3/
现在,我需要从 Ext JS 代码中 运行 这个。所以我为此
创建了另一个 fiddle``http://jsfiddle.net/07kk8fzs/2/
在 Ext JS 版本中,我无法折叠树。折叠需要在update函数内部调用update函数,报错
this.update(d);
-
Uncaught TypeError: this.update is not a function
谁能帮我理解为什么会这样以及如何解决这个问题。
谢谢
您需要将范围存储在构造函数的 属性 中,然后使用它在更新函数中调用 "update"。这是您的 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);