selectpicker不是功能吗?

时间:2020-06-11 08:16:59

标签: javascript jquery json bootstrap-4 bootstrap-selectpicker

我正在使用带有JSON数据的jQuery在网站上进行过滤。昨天,此过滤器运行正常。现在显示错误:

selectpicker不是功能

有人可以帮我解决这个问题吗?

<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>

1 个答案:

答案 0 :(得分:1)

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

我无法进行测试,但是您可以尝试以下操作:

<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>