Meteor.js:向页面添加日期选择器

时间:2015-03-05 18:52:44

标签: meteor

我正努力在我的流星应用程序上获取日期选择器。我测试了通过谷歌搜索找到的很多软件包,但似乎没有一个工作,或者,可能,我做错了。有人能告诉我如何添加日期选择器吗?

非常感谢!

3 个答案:

答案 0 :(得分:3)

我会使用 bootstrap 3 包和 bootstrap 3日期时间选择器包:

$ meteor add twbs:bootstrap
$ meteor add tsega:bootstrap3-datetimepicker 

然后,只需在 HTML 文件中添加表单:

<template name="myTemplate">
    <form>
       <div class="form-group">
          <label for="myInput">Input name</label>
          <div class="input-group datetimepicker">
             <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
             <input name="idInput" id="idInput" class="set-due-date form-control" type="text"/>
           </div>
        </div>
    </form>
</template>

在相应的 JavaScript 文件中,您必须初始化日期时间选择器:

Template.myTemplate.rendered = function(){
    $('.datetimepicker').datetimepicker();
};

如果您的页面中有不同的日期输入(例如):

Template.myTemplate.rendered = function(){
     $('.datetimepicker').each(function(){
           $(this).datetimepicker(); 
     });
}

最后,如果您需要更多选项(如日期格式等),我邀请您阅读Documentation

希望它会对你有所帮助!

答案 1 :(得分:1)

我添加了这些包

拼焊板:自举 jQuery的 rajit:bootstrap3-日期选择

并在模板中使用它

<div class="box-body no-padding">
    <!--The calendar -->
    <div id="calendar" style="width: 100%"></div>
</div><!-- /.box-body -->

并在

下面添加了帮助器
Template.myCalendar.rendered = function() {
    $('#calendar').datepicker();
}

答案 2 :(得分:0)

我使用the one from eonasdon(需要Bootstrap),你可以通过这样做预先打包它:

meteor add hujhax:bootstrap3-datetimepicker