[英]Bootstrap 4 dropdown can’t show selected value
I am using Laravel and trying to incorporate simple bootstrap dropdown on one of the blade templates. 我正在使用Laravel并尝试在其中一个刀片模板上加入简单的bootstrap下拉列表。
The problem I am facing is dropdown gets clicked, shows up all options but when clicked on on of the options, that selected option doesn't get displayed as selected in the dropdown. 我面临的问题是点击下拉,显示所有选项,但是当单击选项时,所选选项不会在下拉列表中显示为选中状态。
I Googled and I can see few posts which say that Jquery.js
should be included prior to bootstrap.js
我用谷歌搜索,我可以看到几个帖子,说在
bootstrap.js
之前应该包含Jquery.js
I am using Laravel mix and not sure how can I specify the order of the scripts which will get included in final app.js
file (if that is the solution to my problem!) 我正在使用Laravel mix并且不确定如何指定将包含在最终
app.js
文件中的脚本的顺序(如果这是我的问题的解决方案!)
Update: After some research, I find following: 更新:经过一些研究,我发现以下内容:
Following dropdown does not work (interestingly even on Bootstrap website https://getbootstrap.com/docs/4.0/components/dropdowns/#single-button-dropdowns ): 下拉列表不起作用(有趣的是甚至在Bootstrap网站https://getbootstrap.com/docs/4.0/components/dropdowns/#single-button-dropdowns ):
<div>
<div class="dropdown" id="field-mapping-dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Please select field
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="#">item 1</a>
<a class="dropdown-item" href="#">item 2</a>
</div>
</div>
</div>
And following does work: 以下工作:
<div>
<label for="pillar">Pillar</label>
<div class="dropdown bootstrap-select margin-left-15px">
<select name="pillar" id="pillar" class="selectpicker">
<option value="">Please select</option>
<option value="">Please select1</option>
<option value="">Please select2</option>
</select>
</div>
</div>
I added require('../../node_modules/bootstrap-select/dist/js/bootstrap-select');
我添加了
require('../../node_modules/bootstrap-select/dist/js/bootstrap-select');
inside resources/js/app.js
内部
resources/js/app.js
Upgrade to Bootstrap 4.1 +. 升级到Bootstrap 4.1 +。 since 4.0 is crappy and does not work.
因为4.0很糟糕而且不起作用。 Even the docs don't work.
即使是文档也行不通。
Well since this is a short answer, your require is weird. 好吧,因为这是一个简短的答案,你的要求是奇怪的。 Mix will auto look in your node_modules folder.
Mix将自动查找node_modules文件夹。
import bootstrapSelect from 'bootstrap-select';
//or
require('bootstrap-select');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.