문제

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?

도움이 되었습니까?

해결책

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 }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top