[英]Meteor: Why my template helper isn't reactive?
I want to get path in order to set active class for active tabs. 我想获取路径以便为活动选项卡设置活动类。 The code works, if I click "refresh" everytime.
如果我每次单击“刷新”,该代码均有效。
Here is my code: 这是我的代码:
JS JS
Template.header.helpers({
isCurrentPage: function(pageName){
var pathArr = window.location.pathname.split("/");
var firstLevelPath = pathArr[1];
return firstLevelPath == pageName
}
});
HTML HTML
<li role="presentation" class="{{#if isCurrentPage 'browse'}}active{{/if}}"><a href="{{pathFor 'browse'}}">Browse</a></li>
Full repo 完整回购
https://github.com/mvaisanen/flashcards https://github.com/mvaisanen/flashcards
Iron.Location.get().path
返回实际路径并且是反应性的,所以我猜你可以使用它
The window object is not reactive then the template does not know about the change. 窗口对象不是反应性的,则模板不知道更改。 Try to use Tracker.autorun around it to have a reactive behavior.
尝试在它周围使用Tracker.autorun来做出反应。
Check this link that contains more about Tracker 检查包含更多有关Tracker的链接
http://docs.meteor.com/#/full/tracker_autorun http://docs.meteor.com/#/full/tracker_autorun
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.