original_string: public function loads($fields = [], $sourceUrls = [], $idField = 'id', $textField = 'text')
      {
          $fieldsStr = implode('.', $fields);
          $urlsStr = implode('^', $sourceUrls);
          $script = <<<EOT
  var fields = '$fieldsStr'.split('.');
  var urls = '$urlsStr'.split('^');
  
  var refreshOptions = function(url, target) {
      $.get(url).then(function(data) {
          target.find("option").remove();
          $(target).select2({
              data: $.map(data, function (d) {
                  d.id = d.$idField;
                  d.text = d.$textField;
                  return d;
              })
          }).trigger('change');
      });
  };
  
  $(document).off('change', "{$this->getElementClassSelector()}");
  $(document).on('change', "{$this->getElementClassSelector()}", function () {
      var _this = this;
      var promises = [];
  
      fields.forEach(function(field, index){
          var target = $(_this).closest('.fields-group').find('.' + fields[index]);
          promises.push(refreshOptions(urls[index] + "?q="+ _this.value, target));
      });
  
      $.when(promises).then(function() {
          console.log('开始更新其它select的选择options');
      });
  });
  EOT;
  
          Admin::script($script);
  
          return $this;
      }
code: public function loads($fields = [], $sourceUrls = [], $idField = 'id', $textField = 'text')
      {
          $fieldsStr = implode('.', $fields);
          $urlsStr = implode('^', $sourceUrls);
          $script = <<<EOT
  var fields = '$fieldsStr'.split('.');
  var urls = '$urlsStr'.split('^');
  
  var refreshOptions = function(url, target) {
      $.get(url).then(function(data) {
          target.find("option").remove();
          $(target).select2({
              data: $.map(data, function (d) {
                  d.id = d.$idField;
                  d.text = d.$textField;
                  return d;
              })
          }).trigger('change');
      });
  };
  
  $(document).off('change', "{$this->getElementClassSelector()}");
  $(document).on('change', "{$this->getElementClassSelector()}", function () {
      var _this = this;
      var promises = [];
  
      fields.forEach(function(field, index){
          var target = $(_this).closest('.fields-group').find('.' + fields[index]);
          promises.push(refreshOptions(urls[index] + "?q="+ _this.value, target));
      });
  
      $.when(promises).then(function() {
          console.log('开始更新其它select的选择options');
      });
  });
  EOT;
  
          Admin::script($script);
  
          return $this;
      }
code_tokens: public function loads ( $ fields = [ ] , $ sourceUrls = [ ] , $ idField = 'id' , $ textField = 'text' ) { $ fieldsStr = implode ( '.' , $ fields ) ; $ urlsStr = implode ( '^' , $ sourceUrls ) ; $ script =  <<<EOT
  var fields = '$fieldsStr'.split('.');
  var urls = '$urlsStr'.split('^');
  
  var refreshOptions = function(url, target) {
      $.get(url).then(function(data) {
          target.find("option").remove();
          $(target).select2({
              data: $.map(data, function (d) {
                  d.id = d.$idField;
                  d.text = d.$textField;
                  return d;
              })
          }).trigger('change');
      });
  };
  
  $(document).off('change', "{$this->getElementClassSelector()}");
  $(document).on('change', "{$this->getElementClassSelector()}", function () {
      var _this = this;
      var promises = [];
  
      fields.forEach(function(field, index){
          var target = $(_this).closest('.fields-group').find('.' + fields[index]);
          promises.push(refreshOptions(urls[index] + "?q="+ _this.value, target));
      });
  
      $.when(promises).then(function() {
          console.log('开始更新其它select的选择options');
      });
  });
  EOT ; Admin :: script ( $ script ) ; return $ this ; }
docstring: Load options for other selects on change.
  
  @param array  $fields
  @param array  $sourceUrls
  @param string $idField
  @param string $textField
  
  @return $this
docstring_tokens: Load options for other selects on change .