流星适当经常使用
Meteor proper constant use
我在文本区域使用WYSIWYG (bootstrap3-wysiwyg5)包。这个包可以正常工作,但是每当渲染页面时,用粗体、斜体等修改文本的菜单就会成倍增加。
是这样的
我认为使用{{#constant}}块会阻止这一点,但它似乎没有做任何事情。
那么,两个问题:
- 在这个实例中我是否错误地使用了{{#constant}}块?
- 如果没有,有什么建议停止这样的渲染情况吗?
代码:
要使用所见即所得编辑器,只需将其添加到您想要使用的任何文本区域。在客户端我有:
Template.announcements.rendered = function(){
$('#announcement_message').wysihtml5({
"font-styles": false, //Font styling, e.g. h1, h2, etc. Default true
"emphasis": true, //Italics, bold, etc. Default true
"lists": true, //(Un)ordered lists, e.g. Bullets, Numbers. Default true
"html": false, //Button which allows you to edit the generated HTML. Default false
"link": true, //Button to insert a link. Default true
"image": false, //Button to insert an image. Default true,
"color": false //Button to change color of font
});;
};
然后在模板中添加:
{{#constant}}
<textarea id="announcement_message" class="form-control" name="message" type="text"></textarea>
{{/constant}}
constant
块通常以这种方式工作,但您的问题在于渲染函数实际运行的次数。如果你在你的Template.announcements.rendered()
里放一个console.log()
,我敢打赌它会出现4次。
这在Meteor的新渲染系统Blaze中不会是一个问题。他们正在解决这个问题。
Ben McMahen有一个关于Meteor的渲染回调的伟大的帖子,在那,他有一个建议的代码块,以确保某些东西只运行一次,它是通过附加一个rendered
属性到模板实例,像这样:
Template.announcements.rendered({
if(!this.rendered) {
// This code only runs once
$('#announcement_message').wysihtml5({
"font-styles": false, //Font styling, e.g. h1, h2, etc. Default true
"emphasis": true, //Italics, bold, etc. Default true
"lists": true, //(Un)ordered lists, e.g. Bullets, Numbers. Default true
"html": false, //Button which allows you to edit the generated HTML. Default false
"link": true, //Button to insert a link. Default true
"image": false, //Button to insert an image. Default true,
"color": false //Button to change color of font
});;
this.rendered = true;
}
});
相关文章:
- 使用流星调用时,可以多次访问流星中的某个函数
- 尝试过滤“;引号"基于'"类别“;使用流星&mongo
- MeteorJS使用流星调用和流星方法时的无限循环
- 如何使用流星模板上的if条件
- 开始使用 流星 - 显示集合
- 将一天中的时间保存为mongodb中的数字,但以人类格式显示(使用流星自动形成)
- 使用流星自动表单预览数据
- 如何使用流星.js的商业主题
- 流星 - 如何使用流星输出复选框值.js
- 使用流星应用程序设置谷歌分析:跟踪未安装错误
- 使用流星角色的优缺点是什么?
- 如何“;惰性负载”;(“需要模块”)使用流星的咖啡脚本
- 如何在typescript文件中使用流星包
- 如何使用流星/javascript从url获取图像
- 在哪里可以使用流星http将POST数据传递到api
- 使用流星框架进行地理定位
- 使用流星角色和铁流星限制视图仅在特定条件下有效
- 使用流星按日期分组
- 使用流星访问阴影DOM聚合物元素
- 使用流星和Angular为单个文档提供3- way数据绑定,而不是集合