0

这是我第一个使用 Javascript 的周末(来自 Matlab 背景),经过一个非常高效的星期六之后,我已经坚持了好几个小时,非常感谢任何帮助!

我试图检测一个下拉框的值,然后从 Parse 后端更新另一个,一个是顶级行业,另一个是子行业。从这里的其他答案来看,这似乎应该很容易,但是当它检测到更改时,它实际上从未更新第二个框。数据从 Parse 到达很好。我在其他部分使用了 Foundation 框架、最新版本的 jQuery 和 Handlebars,如果这能有所作为的话。

的HTML:

<form class="custom">

<div class="large-6 columns">



  <label for="IndustryDropDown">Area of interest</label>
  <select id="IndustryDropDown" class="small">
    <option>All</option>
    <option>Technology</option>
    <option>Services</option>
    <option>Financial</option>
    <option>Consumer goods</option>
    <option>Materials and mining</option>
  </select>

</div>

<div class="large-6 columns">

  <label for="SubIndustryDropDown">Specific interest</label>
  <select id="SubIndustryDropDown" class="small">
  <option>Select Area first</option>
  </select>
</div>

</form>

JS:

$("#IndustryDropDown").change(function(){

  var SubIndustry = Parse.Object.extend("SubIndustry");
  var query = new Parse.Query(SubIndustry);


  // change this to a case statement once working

  if ($(this).val() == "Technology"){

      var Industries = Parse.Object.extend("Industries");
      var industries = new Parse.Query(Industries);
      query.descending("Name");
      query.equalTo("Industry", "Technology")

        query.find({
          success: function(results) {

            $(results).each(function(i,e) {
              var q = e.toJSON();
              console.log(q.Name) // this prints out the Name entries as expected
              $('SubIndustryDropDown').append( new Option(q.Name, q.Name));
            });//for each  

          },//sucess
          error: function(error) {
            console.warn("error finding quote")
}
});
4

1 回答 1

0
$('SubIndustryDropDown').append( new Option(q.Name, q.Name));

jQuery ID selectors require #, otherwise you're selecting an element with that name (no html element exists with that name, but it could happen with xhtml)

So $('#SubIndustryDropDown'). Also, append() needs a parameter that is either an html string, a DOM node, or a jquery object containing that DOM node. I don't know if that Option object is valid for jQuery, but if it fails do something like .append($("<option>").attr("value", q.Name).text(q.Name)) (that's just how I'd generate the html for the option tag, there might be better ways)

于 2013-04-07T20:20:16.280 回答