简体   繁体   English

bootstrap-select:将选项添加到多个选择框后,它无法正确刷新

[英]bootstrap-select: after adding options to multiple select box it doesnt refresh correctly

I am using bootstrap-select plugin ( http://silviomoreto.github.io/bootstrap-select/ ) to provide an option to select multiple values. 我正在使用bootstrap-select插件( http://silviomoreto.github.io/bootstrap-select/ )提供选择多个值的选项。 I have a hash table with letters as key and words starting with corresponding letter as values. 我有一个哈希表,其中字母作为键,单词以对应的字母开头作为值。 I have a drop down with list of letters and once a letter is selected the multi select box should be populated with the words for that letter. 我有一个字母列表下拉列表,选择了一个字母后,应该在多选框中填充该字母的单词。

.cshtml .cshtml

<div class="row word-letter">
    <div class="col-md-3">
        <div class="input-group">
            <input type="text" class="form-control dropdown-text letterVal" placeholder="Select Letter" autocomplete="off" />
            <div class="input-group-btn">
                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                    <span class="caret"></span>
                </button>
                <ul class="dropdown-menu pull-right letterList"></ul>
            </div>
        </div>
    </div>

    <div class="col-md-5">
        <select class="selectpicker" multiple title="No words available"></select>
    </div>
</div>

Once the letter from letterList is selected, the selectpicker should be populated with options corresponding to that letter in wordMap. 一旦选择了letterList中的字母,就应该在selectpicker中填充与wordMap中该字母对应的选项。 And also the default title should change from "No words available" to "Select from following words". 并且默认标题应从“无可用单词”更改为“从后续单词中选择”。 Below is the code snippet, theObject here is jquery handle to the dropdown-menu. 下面是代码片段,theObject是下拉菜单的jquery句柄。

.js .js文件

var wordMap = {
    "A": ["Aware", "Analog"],
    "D": ["Dare", "Digital"],
    "F": ["Flare", "Fist", "Frame"]
};

var selectedLetter = theObject.text(); 
var wordSelectElem = theObject.parents('.word-letter').find('.selectpicker')
        if (wordSelectElem.length > 0) {

            $.each(wordMap[selectedLetter], function (key, value) {
                wordSelectElem.append($('<option>' + value + '</option>'));
            });
            if (wordSelectElem.size() > 0) {
                wordSelectElem.prop('title', "Select from following words");
            }
            wordSelectElem.selectpicker('refresh');
        }

When I run this in IE, I am seeing that the selectpicker adds the words in a weird way as below (eg: when D selected): 当我在IE中运行此代码时,我看到selectpicker以一种奇怪的方式添加了单词,如下所示(例如:选择D时): 选择填充错误

How can I fix this? 我怎样才能解决这个问题?

My best guess, from what I see above, is that you have a bit of errant CSS that is causing the problem. 我从上面看到的最好的猜测是,您有一些导致问题的错误CSS。 This would be very easy to locate using FireBug or any other browser based developer tools that will allow you to see what CSS is being applied to that element (or perhaps the surrounding elements). 使用FireBug或任何其他基于浏览器的开发人员工具,这将很容易找到,这将使您能够看到正在对该元素(或周围的元素)应用什么CSS。

If you can even post a link to the page in question (send it privately if there is concern about a public link) and I (or anyone else) can look at the elements in question. 如果您甚至可以发布到相关页面的链接(如果对公共链接存在担忧,请私下发送),而我(或其他人)可以查看相关元素。

If you try to reproduce this in JSFiddle and can't then all the more reason suspect the problem is local your CSS or code. 如果您尝试在JSFiddle中重现此错误,则不能再以其他理由怀疑问题出在您的CSS或代码本地。 Try removing all CSS files on the page except the Bootstrap.css and whatever CSS file comes with this control. 尝试删除页面上除Bootstrap.css和此控件随附的任何CSS文件以外的所有CSS文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM