gpt4 book ai didi

javascript - 铁 :Router add events on change router

转载 作者:行者123 更新时间:2023-11-27 23:04:30 27 4
gpt4 key购买 nike

我想在当前的不同路线上添加类。

我的脚本:

Template.layout.rendered({

rowClass: function() {

var blockGridContent = [
'blogPostDetail',
'contact'
];

// Si on est sur l'une des pages de 'blockGridContent'
if (_.contains(blockGridContent, routeCurrent)) {

return 'block-grid';

}

}

})

这段代码运行良好,但只能加载。如果我进入“测试”并更改页面,该类(class)仍然保留。

我想我必须从服务器或iron:路由器检查,但我不知道如何。

你有想法吗?

谢谢! :)

最佳答案

尝试从组件内部访问当前路由是一种不好的做法,这使得它们更难以维护。相反,您应该向他们传递所有需要的数据。

就您而言,您可以使用 Controller 的 data 方法来实现您所需要的:

BlockGridController = RouteController.extend({
...
data: function() {
return {
...
layout: {style: 'block-grid'},
};
},
});

然后在布局模板中访问它:

<div class="{{layout.style}}">

关于javascript - 铁 :Router add events on change router,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36718203/

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