3

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

这是我的 ( d3js )代码小提琴

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

//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');
        }
    }
});
4

1 回答 1

0

只需使用 $(t) 而不是 $('g.node')

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

    }

在此处查看演示

于 2015-03-27T12:19:23.510 回答