selectpicker 不是函数?

selectpicker is not a function?

我正在使用 jQuery 和 JSON 数据在网站上开发过滤器。昨天这个过滤器工作正常。现在显示错误:

selectpicker is not a function

谁能帮我解决这个问题?

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript" src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.17/js/bootstrap-select.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/jquery.validate.min.js"></script>
<script type="text/javascript" src="js/custom.js"></script>

<script>
  var dataLoad = <?php echo json_encode( $filterData); ?>
  console.log(dataLoad);
  var body;
  var model;
  var variant;

  $('#selectBody').empty().append('<option selected="selected" value="">Body</option>');
  Object.entries(dataLoad).forEach(([key, value]) => {
    // console.log(`${key} ${value}`);
    $('#selectBody').append(`<option  value="${key}">${key}</option>`);
  });

  function changeType(val) {
    $('.selectpicker').selectpicker('refresh');
    body = val.value
    $('#selectModel').empty().append('<option selected="selected" value="">Model</option>');
    Object.entries(dataLoad).forEach(([key, value]) => {
      if (key === val.value) {
        Object.entries(value).forEach(([k, v]) => {
          $('#selectModel').append(`<option  value="${k}">${k}</option>`);
        });
      }
    });
    $('.selectpicker').selectpicker('refresh');
  }

  function changeModel(val) {
    model = val.value
    $('#selectVariant').empty().append('<option selected="selected" value="">Trim</option>');
    Object.entries(dataLoad).forEach(([key, value]) => {
      if (body === key) {
        Object.entries(value).forEach(([k, v]) => {
          if (k === val.value) {
            Object.entries(v).forEach(([kV, vV]) => {
              $('#selectVariant').append(`<option  value="${kV}">${kV}</option>`);
            });
          }
        });
      }
    });
    $('.selectpicker').selectpicker('refresh');
  }

  function changeVariant(val) {
    model = val.value
    console.log(model, "-------------")
    $('#selectTransmission').empty().append('<option selected="selected" value="">Transmission</option>');
    Object.entries(dataLoad).forEach(([key, value]) => {
      if (body === key) {
        Object.entries(value).forEach(([k, v]) => {
          console.log(k, " -------:", model)
          if (k === model) {
            Object.entries(v).forEach(([kV, vV]) => {
              if (kV === val.value) {
                console.log(value, "--------------------")
                Object.entries(vV).forEach(([kT, vT]) => {
                  $('#selectTransmission').append(`<option  value="${kT}">${kT}</option>`);
                });
              }
            });
          }
        });
      }
    });

    $('.selectpicker').selectpicker('refresh');
  }
</script>

您需要将 bootstrap-select.min.js 移动到所有 jquery 导入的末尾以重写排除函数。

我无法进行测试,但你可以试试这个:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript" src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/jquery.validate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.17/js/bootstrap-select.min.js"></script>
<script type="text/javascript" src="js/custom.js"></script>