0

I am working with Dart and JQuery. In the view I try to use select2 for a ComboBox component,my code is:

<div class="form-group">
  <label class="control-label col-md-3 col-sm-3 col-xs-12">Select</label>
  <div class="col-md-9 col-sm-9 col-xs-12">
   <select class="select_cities form-control" tabindex="-1">
    <option value="NY">New York</option>
    <option value="LA">Los Angeles</option>
    <option value="CH">Chicago</option>
    <option value="HO">Houston</option>
    <option value="PH">Phoenix</option>
   </select>
  </div>
</div>
...
<script>
  $(document).ready(function () {
     $(".select_cities").select2({
        placeholder: "Select a City",
        allowClear: true
      });
   });
</script>

My question is, how can I call this function in Dart? because when the view is loaded the select_cities component doesn't work, I suppose that every jquery function has to be called in Dart file.

Thanks for all

Ronald
  • 291
  • 3
  • 7
  • 23
  • 1
    The issue is probably that the element is added to the DOM after ` $(".select_cities").select2({ ...` is called. There are several similar questions anwered already. For example http://stackoverflow.com/questions/20755337/how-to-call-a-jquery-function-from-dart – Günter Zöchbauer Apr 06 '16 at 18:22
  • You are OK, I use "js.context.callMethod" as your example. – Ronald Apr 09 '16 at 05:49

0 Answers0