简体   繁体   English

如何将Bootstrap日期选择器添加为Ember组件

[英]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.

相关问题 如何添加日期和时间选择器引导插件? - How to add date and time picker bootstrap plugin? 如何在Bootstrap日期时间选择器中添加秒数 - How to add seconds to Bootstrap date time picker 引导程序:如何向引导程序日期选择器添加自定义按钮? - Bootstrap: How to add custom button to bootstrap date picker? 如何在 mvc 视图中添加引导日期时间选择器 - How to add bootstrap date time picker in mvc view 用于Twitter Bootstrap的Django和日期范围选择器组件 - Django and date range picker component for Twitter Bootstrap 如何将日期选择器或任何常规jQuery插件添加到Ember-CLI App - How to add date picker or any general jQuery plugin to Ember-CLI App Bootstrap Date Range Picker -&gt; Single Date Picker: 如何设置日期 - Bootstrap Date Range Picker -> Single Date Picker: How to set a Date 如何在引导日期选择器中突出显示自定义日期 - How to highlight custom date in bootstrap date picker 如何在Bootstrap日期选择器中更改日期格式? - How to change the date format in Bootstrap date picker? 如何与日期选择器一起添加时间选择器 - how to add time picker along with date picker
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM