我使用我正在更新的d3选择器意外地将相同的事件处理程序覆盖在svg元素之上.
add_listeners = function() { d3.selectAll(".nodes").on("click", function() { //Event handler to highlight clicked d3 element }); jQuery('#some_navigation_button').on('click', function() { //Event handler }); jQuery('#some_refresh_button').on('click', function() { //Event handler that re-draws some d3 svg elements }); //... 5 other navigation and d3 handlers }
将add_listeners()
重新添加相同的处理程序.所以我试过了
add_listeners = function() { d3.selectAll(".nodes").off(); jQuery('#some_navigation_button').off(); jQuery('#some_refresh_button').off(); d3.selectAll(".nodes").on("click", function() { //Event handler }); jQuery('#some_navigation_button').on('click', function() { //Event handler }); jQuery('#some_refresh_button').on('click', function() { //Event handler that re-draws some d3 svg elements }); //... 5 other navigation and d3 handlers }
,没有运气.
注意:使用d3 v2.9.1,