作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在关注discovermeteor.com教程,尝试发挥创意并向其中添加我自己的东西。我想做的一件事是使用 jQuery 设置一个 session 值用作页面标题(但不确定这是否 100% 有意义)。
所以我一直在尝试在满足某些条件时在文档就绪时触发 session.set,但它似乎不起作用。
我的代码示例:
Template.layout.helpers({
pageTitle: function() { return Session.get('pageTitle'); }
})
jQuery(document).ready(function($) {
if ( $('section#main').hasClass('postlist')) {
Session.set('pageTitle', 'Posts list');
};
});
所以,我的问题是,如何使用 jQuery 和 Meteor?我可以按照我习惯的方式使用 jQuery,还是有什么特别需要注意的地方?非常感谢
最佳答案
在 Meteor 中,我们不使用 $(document).ready,相反,您应该使用等效的 Meteor.startup :
Meteor.startup(function() {
if ( $('section#main').hasClass('postlist')) {
Session.set('pageTitle', 'Posts list');
};
});
关于jquery - 如何将 jQuery 与 Meteor 框架结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25340582/
我是一名优秀的程序员,十分优秀!