简体   繁体   中英

Load Data on `ready` in Dashing Widget's Coffeescript

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 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM