Javascript 如何检查当前是否安装了Meteor软件包?
我需要检查我的应用程序中是否安装了软件包Javascript 如何检查当前是否安装了Meteor软件包?,javascript,meteor,meteor-blaze,Javascript,Meteor,Meteor Blaze,我需要检查我的应用程序中是否安装了软件包my package:notification 然后才使用另一个模板(这是此包的一部分) 大概是这样的: <template name="example"> {{#if hasNotificationPackage}} {{>notification}} {{/if}} </template> {{{#如果hasNotificationPackage} {{>通知} {{/if} 如何做到
my package:notification
然后才使用另一个模板(这是此包的一部分)
大概是这样的:
<template name="example">
{{#if hasNotificationPackage}}
{{>notification}}
{{/if}}
</template>
{{{#如果hasNotificationPackage}
{{>通知}
{{/if}
如何做到这一点?假设您的包使用的对象/变量在项目中是可访问的。您只需要为解决方案编写一个助手
Template.example.helpers({
hasNotificationPackage: function(){
return (PackageObj) ? true: false; //PackageObj is your package permissible object
}
});
Meteor提供了一个名为
Package
的全局对象,其中包含所有Meteor包导出
因此,您可以使用
Template.example.helpers({
hasNotificationPackage() {
return (typeof Package['my-package:notification'] === 'object');
}
});
我不确定这种方式是否应该经常使用,特别是在生产中。能否给我一个示例,说明如何创建
PackageObj
?我/你不会创建对象。使此对象可访问的是包作者。这里的PackageObj
只是一个例子