score:2
This seems to be more of a JavaScript scope issue. Is tree_data
already exposed to other functions (e.g. in the jQuery event handler, can you console.log(tree_data
)? If so, then we just need an external reference to update
.
A quick way is to assign it to the global window
scope:
window.update = function(source) { ...
Of course this isn's not optimal, but it does help us narrow down your issue.
If that works, then we just need to declare a variable outside the scope of your build: function(tree_data)
and then inside, on line 65, assign it to update
:
var externalReferenceToUpdate;
[...]
build: function(tree_data) {
[...]
var update = function(source) {
[...]
};
externalReferenceToUpdate = update;
update(root); // moved this due to function expression vs. declaration
[...]
}
As you noticed, we had to move update(root)
. This is because we've "made" the function using a different method. There's a whole other Stack Overflow discussion on the ways to declare functions and their scope issues. Essentially with the second way (var name = function()
), the function is not "hoisted" to the top of its scope, so we had to call update
after we assigned it to a variable.
Hope this helps!
PS In that other discussion, skim over the first answer and actually focus on the second answer by Eugene.
Source: stackoverflow.com
Related Query
- D3.js event handler on external dom element to trigger redraw of svg tree nodes
- SVG element loses event handlers if moved around the DOM
- programmatically trigger click event in svg rect element
- Can svg element trigger click event of svg elements under itself?
- How to access the DOM element that correlates to a D3 SVG object?
- How do you make an SVG element mouse event bubble up through another element?
- D3.js v4: Access current DOM element in ES6 arrow function event listener
- Giving an element more than one event handler by selecting it using different selectors
- D3 new data at .data() makes svg to redraw instead of updating nodes position
- How can I pass attributes of an SVG element to a new event in D3?
- How to assign click event to every svg element in d3js
- how to add dragend event on svg element
- Best solution to label nodes in SVG dynamic tree (using D3.js)
- appending entire svg to dom element leads to Exception... "String contains an invalid character" code: "5"
- How can I get the dom svg element from d3 node data?
- Triggering a Click Event on an SVG element
- Trigger hover event on <g> element in d3 graph
- Wheel event is not fired on a SVG group element in Safari
- Selecting element in external SVG
- how to set collision between nodes and other svg element in D3.js
- Always trigger event when element of a class is clicked
- Attaching 'onclick' event to SVG element 'rect' after loading
- Making An HTML element inside a D3-Tip Trigger Click Event
- Keep DOM event handlers when writing an SVG to file
- Select an element in contained DOM tree using d3.js
- d3 event handler on node not in HTML DOM
- How to unbind an onload event on an external SVG after it was initially completed?
- Process and send mouse event beneath the SVG element
- How to forcefully call the drag event right after the creation of an dom element in d3?
- D3 force diagram - how to trigger event when nodes stop repositioning
More Query from same tag
- d3js zoom + drag causes conflict
- Get attribute x for axis' text element
- How to modify the content of an svg based dom using nodejs, d3 and jsdom?
- Dynamically display images in D3
- Set y-axis maximum label to one tick increment higher in NVD3
- D3 doesn't load a CSV file from an external URL
- Reading text file with special characters using d3.request
- Control axis tick number in D3
- How to align d3js tooltip in center of time divisions?
- How to filter views with an opacity range in d3/dc.js?
- How do I zoom/pan on enlarged canvas using d3?
- Gremlin: Find all the paths between two nodes and transform the query result into JSON format
- D3 how to select element by ID when there is a dot in ID
- SVG D3 image resize issue
- svg bar chart fails to render on plnkr
- Convert scatterChart into lineChart
- Check two arrays for a JSON property within them
- How to remove white line in d3.js legnd
- Load basic CSV data to D3
- How to implement Bubble Chart / Circle Packing in React Native?
- C3 line chart: compress or break interval between distant points
- How to use D3js on server side to generate SVG directly?
- D3: Create a grouped bar chart from json objects
- Grouping nodes in force directed graphs in d3.js
- D3.js - How can I prevent Circles & Text Overlapping
- circle location different when zoom or drag the d3 map?
- d3 Topojson debugging transformations
- Formatting JSON for C3.js
- Vega lite api miss-behaving
- D3.js csv Filter for Interactivity