通过单击d3.js中的节点来删除和添加节点

时间:2013-03-26 06:50:09

标签: jquery d3.js

如何在我的代码中添加或删除onclick事件的节点和链接?

这是我的{d3jscode fiddle

如何使用:右键单击任何节点并单击删除它删除所有节点但没有链接。
但我想只删除一个节点,并点击要删除的链接。

//right click menu items
$('g.node').contextMenu('cntxtMenu',
{
    itemStyle:
    {
        fontFamily : 'Arial',
        fontSize: '13px'
    },
    bindings:
    {
        'open': function(t) {
            alert(t.__data__.name);
        },
        'email': function(t) {
            alert('Trigger was '+t.__data__.name+'\nAction was Email');
        },
        'save': function(t) {
            alert('Trigger was '+t.__data__.name+'\nAction was Save');
        },
        'delete': function(t) {
            $('g.node').remove();
            //alert('Trigger was '+t.__data__.name+'\nAction was Delete');
        }
    }
});

1 个答案:

答案 0 :(得分:0)

只需使用$(t)代替$('g.node')

   'delete': function(t) {
        $(t).remove();

    }

See Demo Here