[英]How to add Bootstrap Date Picker as Ember Component
One of the things I struggle the most with is taking existing libraries and adding them to my Ember project. 我最努力的事情之一就是将现有库添加到我的Ember项目中。 I am currently trying to add the Bootstrap Date Picker as an Ember component but I can not get it to behave correctly. 我目前正在尝试将Bootstrap日期选择器添加为Ember组件,但无法使其正常运行。
I have added the Bootstrap JS files to my Vendor folder and added the following to ember-cli-build: 我已将Bootstrap JS文件添加到我的Vendor文件夹中,并将以下内容添加到ember-cli-build中:
app.import('vendor/datepicker/bootstrap-datepicker.min.js');
Then I have created a component pod called date_picker. 然后,我创建了一个名为date_picker的组件容器。 The template for the component is as follows: 该组件的模板如下:
<div class="input-group date" data-provide="datepicker" data-date-format="dd/mm/yyyy">
<input type="text" class="form-control">
<div class="input-group-addon">
<span class="glyphicon glyphicon-th"></span>
</div>
</div>
The JS file for the component is currently: 该组件的JS文件当前为:
import Component from '@ember/component';
export default Component.extend({
addDate(){
$('.datepicker').datepicker({
format: 'dd/mm/yyyy',
startDate: '-3d',
autoclose: true
});
}
});
The component is called in the main template with {{date-picker}}
. 该组件在主模板中使用{{date-picker}}
调用。 The above does render a date picker on the screen but one that does not behave correctly. 上面的方法确实在屏幕上呈现了一个日期选择器,但是其行为不正确。 It does not auto close for example and whilst the format is correct, it does not go cycle through months or always select the correct date on a button click. 例如,它不会自动关闭,并且在格式正确的同时,它不会循环显示几个月,也不会始终在单击按钮时选择正确的日期。
Is there a step I have missed in integrating this into an Ember project? 将它集成到Ember项目中,我错过了什么步骤吗?
Have you considered using the existing addon for this? 您是否考虑过使用现有的插件? https://github.com/soulim/ember-cli-bootstrap-datepicker https://github.com/soulim/ember-cli-bootstrap-datepicker
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.