Reputation: 14144
How do you get data to get polled on startup of a dashing widget?
ready
is called when the widget is done being rendered.
class Dashing.Tagcloud extends Dashing.Widget
ready: ->
onData: (data) ->
The widget I've built uses D3 to display data. On initial load, the widget is blank. The successive event poll will populate the D3 widget. All other widgets get their data early on. Is there a way to trigger an immediate query for data?
Is D3 and/or jQuery just not ready by the time this gets called on the first run?
Upvotes: 2
Views: 2175
Reputation: 24478
You could emit your data in hidden DOM elements in your widget's markup:
<ul style="display: hidden" data-foreach-item="items">
<li>
<span class="name" data-bind="item.name"></span>
<span class="count" data-bind="item.count"></span>
</li>
</ul>
Then collect the data from the DOM instead:
tagData = ->
items = $(@node).find('ul.items li')
for i in items
name = $(i).find('span.name').text()
count = parseInt $(i).find('span.count').text()
{ name: name, count: count }
Upvotes: 3