简体   繁体   English

在Ext JS 4.2中创建D3可折叠树

[英]Creating D3 collapsible tree within Ext JS 4.2

I have the following D3 code which works as expected. 我有以下D3代码,可以正常工作。 Tree is rendered and can be expanded and collapsed on clicking the nodes. 树被渲染,单击节点即可展开和折叠。

`` http://jsfiddle.net/6Ldad16n/3/ `` http://jsfiddle.net/6Ldad16n/3/

Now, I need to run this from within Ext JS code. 现在,我需要在Ext JS代码中运行它。 So I created another fiddle for this 所以我为此创造了另一个小提琴

`` http://jsfiddle.net/07kk8fzs/2/ `` http://jsfiddle.net/07kk8fzs/2/

In the Ext JS version, I am not able to collapse the tree. 在Ext JS版本中,我无法折叠树。 Collapsing requires calling the update function from inside the update function, which is giving an error 折叠需要从update函数内部调用update函数,这会导致错误

 this.update(d);

- -

Uncaught TypeError: this.update is not a function

Can someone please help me understand why this is happening and how to get around this. 有人可以帮我了解为什么会这样以及如何解决这个问题。

Thank you 谢谢

You need to store the scope in a property on the constructor, and then use it to call "update" within the update function. 您需要将范围存储在构造函数的属性中,然后使用它在update函数中调用“ update”。 Here is your fiddle fixed: http://jsfiddle.net/kqr57ad3/ 这是您固定的小提琴: 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;
        },

Then inside the update function use this reference: 然后在更新函数中使用此引用:

me.update(d);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM