【问题标题】:Bootstrap selectpicker MVC dropdown livesearch引导选择选择器 MVC 下拉实时搜索
【发布时间】:2017-03-10 10:38:36
【问题描述】:

我很确定我的问题与脚本参考有关。

我已将其添加到我的捆绑包中

bundles.Add(new ScriptBundle("~/bundles/bootstrap-select").Include(
    "~/Scripts/bootstrap-select.js",
    "~/Scripts/bootstrap-select.min.js"));

这是我的观点代码:

<script type="text/javascript">
    $(document).ready(function () {
        $('.selectpicker').selectpicker({
            liveSearch: true,
            showSubtext: true
        });
    });

HTML 格式:

@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
    @Html.LabelFor(model => model.SagId, "SagId", htmlAttributes: new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        @Html.DropDownListFor(x => x.SagId,(IEnumerable<SelectListItem>)ViewBag.SagId,
            new
            {
                @class = "form-control selectpicker",
                data_show_subtext = "true",
                data_live_search = "true"
            })
        @Html.ValidationMessageFor(model => model.SagId, "", new { @class = "text-danger" })
    </div>
</div>

我从我的视图包中获取了列表,它工作正常。但我似乎无法解决这个问题。

更新: 试图在视图中手动添加引用。现在保管箱完全消失了,我得到了这些错误:

Uncaught TypeError: Cannot read property 'valHooks' of undefined
at bootstrap-select.min.js:7
at bootstrap-select.min.js:8
at bootstrap-select.min.js:7
at bootstrap-select.min.js:7

Create:78 Uncaught ReferenceError: $ is not defined 创建时:78

【问题讨论】:

  • 什么问题不能解决?
  • 它不会将样式/javascript 应用到我的下拉列表中。
  • 我希望它看起来像这样:jsfiddle.net/codeandcloud/a5r2vyu2/1
  • 你没有包含任何样式信息,这个问题中的代码和你的问题完全无关
  • @Liam 我现在刚刚添加了一些,我的问题是我无法将“selectpicker”样式应用于我的 DropDownBox。

标签: javascript asp.net-mvc bootstrap-selectpicker


【解决方案1】:

首先,您只想添加一个引用;从 JS 开始;在发布模式下构建时,它会找到 min.js。

bundles.Add(new ScriptBundle("~/bundles/bootstrap-select").Include(
    "~/Scripts/bootstrap-select.js"));

这是注册同一个脚本,会出现这些问题。

其次,看起来这个包是在您定义 JQuery 之前定义的。所以 $ 没有定义很可能是因为引导选择脚本和使用必须在 JQuery 初始化之后。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-30
    • 1970-01-01
    • 2021-02-14
    • 2020-11-23
    • 2019-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多