流星检查模板是否存在

时间:2015-06-06 16:43:57

标签: meteor iron-router

我有使用Iron-Router的Meteor应用程序,其中渲染的屏幕基于URL是动态的 我有两个参数来自网址stationscreen

在路由代码中:
this.render(stationParam+screenParam, {to: 'content'});

但是,我希望能够检查模板stationParam+screenParam是否存在。

这可能吗?

1 个答案:

答案 0 :(得分:1)

所有模板都存储为全局对象Template的字段。那么问题是:如何检查这个全局对象是否具有给定字段?

您有多种方法可以做到这一点。我个人最喜欢使用underscore

if (_.has(Template, stationParam + screenParam)) { /* ... */ }

下划线包含在Meteor中。如果您想在套餐中使用它,请不要忘记api.use('underscore')回调中的describe

另请参阅:Determining if a javascript object has a given property