何时在Meteor中声明一个日期选择器,启动或渲染

时间:2013-06-19 17:19:18

标签: meteor

我是Meteor的新手,并试图制作一个表格制作者(mforms): https://github.com/miguelalarcos/mforms

我有一个关于何时应该声明输入是一个日期选择器的问题:

$('.'+form_name+'_attr_date').datepicker(format: 'dd-mm-yyyy', autoclose:true)

我不知道更好的地方是在Meteor.startup还是在template.rendered。 同样用于声明输入文本的函数源。

提前致谢。

1 个答案:

答案 0 :(得分:1)

我会把它放在template.rendered中,因为它只会在用户使用该模板时运行。如果你把它放在启动中它将为每个用户运行 - 即使该用户从未使用该日期选择器的模板。此外,启动内部的代码在服务器和客户端上运行。在服务器上运行此代码没有意义。

来自文档:

rendered

This callback is called once when an instance of Template.myTemplate is rendered into DOM nodes and put into the document for the first time, and again each time any part of the template is re-rendered.

startup

Run code when a client or a server starts.

On a server, the function will run as soon as the server process is finished starting.
On a client, the function will run as soon as the DOM is ready.