我是 Meteorjs 的新手,但发现它很好用。
我想知道根据路由/url 隐藏模板元素的最佳方法是什么。因为我想在其他地方再次使用相同的模板,但其中没有某些元素。
谢谢
我的代码根据以下解决方案
我的 helper
Template.postItem.helpers({
ownPost: function() {
return this.userId === Meteor.userId();
},
commentsCount: function() {
return Comments.find({postId: this._id}).count();
},
routeNameEqual: function(name){
var routeName= Router.current().route.getName();
return routeName === name;
}
});
我的html
{{#if routeNameEqual 'postsList2' }}
<a href="{{pathFor 'postPage'}}" class="discuss btn btn-default">Learn More</a>
{{else}}
{{/if}}
关键!!它是路由名称而不是路由路径
最佳答案
如果您使用 iron:router package , 你可以使用。
if(Router.current().location.get().path == 'some check'){
$('#button').hide();//use jQuery
}else{
$('#show').hide();//use jQuery
}
你也标记了 javascript,所以这是另一个使用 javascript 的解决方案
if(document.URL == 'some check'){ // or use window.location.href
$('#button').hide();//use jQuery
}else{
$('#show').hide();//use jQuery
}
关于javascript - 如何在 Meteorjs 的特定 URL 路径中隐藏模板上的按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29566614/