简体   繁体   中英

Pulling data from a widget in Dashing

I created a widget with a drop down menu and i want to update my ruby query with the value selected in the HTML drop down menu. I am currently using nokogiri to pull the localhost dashboard. nokogiri is able to pull the data from the sample.erb. However, the HTML files that contain the actual information (including the drop down) is not grabbed by nokogiri. the HTML grabbed stops with the data-binding div, nothing inside of that appears when i print out the nokogiri pull. Is there anyway i can grab the entire HTML or pass the value to the ruby from the HTML or coffeescript?

In your widget, you need to grab the data from the DOM. nokogiri can only grab the server-side HTML that you're rendering (what is sent to the client).

The HTML with the data that the user is selecting options in is actually called the DOM, which you can get information from using JavaScript -- or in this case, coffeescript.

Say you have a dropdown like this:

<select id='day-of-week'>

You can bind a handler to it's change event and respond to it like this:

dropdown = $('#day-of-week'); // Use jQuery to get the select by id
dropdown.on 'change', () ->
  selectedValue = $(this).val(); // jQuery to get selected value of dropdown

You probably want to learn a bit more about HTML / JS before embarking on your widget-building journey. Here's some documentation on the DOM to get you started:

https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model

Good luck!

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