gpt4 book ai didi

jquery - 如何将 jQuery 与 Meteor 框架结合使用

转载 作者:行者123 更新时间:2023-12-01 03:39:11 24 4
gpt4 key购买 nike

我正在关注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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com