简体   繁体   English

bootstrap-sass multiselect事件冲突

[英]bootstrap-sass multiselect event conflict

I've got a strange issue using bootstrap-sass and bootstrap-multiselect . 我使用bootstrap-sassbootstrap-multiselect有一个奇怪的问题。 Seems like bootstrap-sass event handlers block multiselect handlers for dropdown etc. 看起来像bootstrap-sass事件处理程序阻止多项选择处理程序下拉等。

This packages installed via bower: 这个包通过凉亭安装:

'bootstrap-sass-official#3.3.1',
'bootstrap-multiselect'

App built on django and python, so template that binds scripts to the page: 应用程序构建在django和python上,所以模板将脚本绑定到页面:

{% compress js %}
    <script src="{% static 'jquery/dist/jquery.js' %}"></script>
    <script src="{% static 'bootstrap-sass/assets/javascripts/bootstrap.js' %}"></script>
{% endcompress %}

binding script on a specific page using: 特定页面上的绑定脚本使用:

{% block extrajs %}
    <script src="{{ STATIC_URL }}bower_components/bootstrap-multiselect/dist/js/bootstrap-multiselect.js"
            type="text/javascript" charset="utf-8"></script>
{% endblock %}

crearing multiselect control: crearing multiselect控制:

$('.multiselect').multiselect()

Nothing special. 没什么特别的。 But when i try to use multiselect control on UI it doesn't drop down. 但是,当我尝试在UI上使用多选控件时,它不会下降。 No errors in console. 控制台没有错误。

After some surfing through the code i figured that there are some event handlers that preventing multiselect handlers from executing: 在浏览代码之后,我发现有一些事件处理程序会阻止多选处理程序执行:

  // APPLY TO STANDARD DROPDOWN ELEMENTS
  // ===================================

  $(document)
    .on('click.bs.dropdown.data-api', clearMenus)
    .on('click.bs.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })
    .on('click.bs.dropdown.data-api', toggle, Dropdown.prototype.toggle)
    .on('keydown.bs.dropdown.data-api', toggle, Dropdown.prototype.keydown)
    .on('keydown.bs.dropdown.data-api', '[role="menu"]', Dropdown.prototype.keydown)
    .on('keydown.bs.dropdown.data-api', '[role="listbox"]', Dropdown.prototype.keydown)

so, the tricky solution was to switch off the standard event handlers first on the page where multiselect used: 所以,棘手的解决方案是首先在使用多选的页面上关闭标准事件处理程序:

$(document)
     .off('click.bs.dropdown.data-api')
     .off('keydown.bs.dropdown.data-api')

Which seems a bit hacky and not the best solution to me. 这看起来有点hacky并不是我的最佳解决方案。

Are there native ways to resolve this conflict? 是否存在解决此冲突的本地方法? Thanx. 感谢名单。

Figured that Bootstrap is linked twice to the page. 认为Bootstrap链接两次到页面。 Explicitly as shown above and implicitly through stepoftheweb.com themes bundled script (i omitted this detail in the question, i thought it doesn't matter) 显式如上所示并隐式通过stepoftheweb.com主题捆绑脚本(我在问题中省略了这个细节,我觉得没关系)

So, i removed first script linking to the page and now it works fine. 所以,我删除了链接到页面的第一个脚本,现在它工作正常。

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

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