gpt4 book ai didi

meteor - 将数据从 Iron 路由器传递到模板助手

转载 作者:行者123 更新时间:2023-12-02 08:56:02 26 4
gpt4 key购买 nike

我正在尝试将iron路由器数据中的categoryId传递到meteor中的模板助手中。

这是我的路由器代码:

Router.route('/lessons/:categoryId', function() {
this.subscribe('lessons');
this.render('Lessons', {
data: {
categoryId: this.params.categoryId
}
});

这是我的模板代码:

Template.Lessons.helpers({
lessons: function () {
console.log('CategoryId: '+categoryId);
}
});

如何正确访问在iron路由器中创建的categoryId?

非常感谢您的帮助。

最佳答案

来自路由器的

data 为您的模板提供上下文 (this)。要从助手访问 categoryId,请使用 this.categoryId:

Template.Lessons.helpers({
lessons: function() {
console.log('CategoryId: ' + this.categoryId);
}
});

您还可以通过以下方式访问路由器数据:

Template.instance().data.categoryId;

关于meteor - 将数据从 Iron 路由器传递到模板助手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29372652/

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