如何让 Twitter 引导程序日期选择器与 Meteor 一起使用?

问题描述:

我更愿意使用 Bootstrap 的 Meteor 包实现而不是 less files 版本,但我很想让 datepicker 工作.

I would rather use the Meteor package implementation of Bootstrap rather than the less files version but I am having a hell of a time getting a datepicker to work.

似乎有三个不同状态的版本,最后一个由 Aymkdn 编译并准备就绪.

There seem to be three versions in varying states with the last one by Aymkdn being compiled and ready to go.

http://www.eyecon.ro/bootstrap-datepicker/

https://github.com/eternicode/bootstrap-datepicker/

https://github.com/Aymkdn/Datepicker-for-Bootstrap

Aymkdn 的版本在纯香草 html 中运行良好,但不能从 Meteor 提供,我正在花大量时间找出原因.

The version by Aymkdn works fine in plain vanilla html but not served from Meteor and I am having a helluva time figuring out why.

我想将 Aymkdn 与 Meteor 一起使用,但我无法让它工作.我认为这可能与 Meteor 中的 js 加载顺序或 DOM 渲染有关.对我如何让它发挥作用有什么见解吗?

I would like to use the one by Aymkdn with Meteor but I cannot get it to work. I think it may have to do with either the js loading order in Meteor or the DOM rendering. Any insights into how I can get this to work?

谢谢史蒂夫

当这个问题最初发布时,也许这种方法不可用,但我在呈现其模板时初始化日期选择器.

Perhaps this approach wasn't available when this question was originally posted, but I'm initializing the datepicker when its template is rendered.

Template.templateName.rendered = function() {
    $('#datepicker').datepicker();
}

这是活动的链接:http://docs.meteor.com/#template_rendered一个>

使用这种方法,我不需要维护会话属性或处理焦点事件.当模板被卸载并返回时,Prashant 的解决方案对我不起作用,因为会话属性被触发.我还遇到了一个问题,即数据选择器在第一次获得焦点时没有显示.

With this approach, I don't have maintain a session property or handle focus events. Prashant's solution didn't work for me when the template was unloaded and returned to since the session property was tripped. I also had an issue wherein the datapicker didn't display the first time it got focus.

是的,每次呈现模板时都会初始化数据选择器,但我认为这没关系,因为我很确定模板资源在它们之间导航时无论如何都会被清理.

Yes, the datapicker will get initialized each time the template is rendered, but I think that's okay since I'm pretty sure template resources are cleaned up when navigating between them anyway.