Javascript 如何使用CollectionFS减少对Handlebar中TemplateHandler的调用数?

Javascript 如何使用CollectionFS减少对Handlebar中TemplateHandler的调用数?,javascript,meteor,handlebars.js,Javascript,Meteor,Handlebars.js,任何人都有任何想法,以减少呼叫传记在我的车把模板(使用流星)。{{cfsFileUrl}}是需要当前文件上下文的CollectionFS帮助程序,因此如果没有{{{with BioPic owner}},它将无法工作。给传记片打两次电话似乎有点多余 <template name="showBioPic"> {{#if BioPic owner}} {{#with BioPic owner}} <img src="{

任何人都有任何想法,以减少呼叫传记在我的车把模板(使用流星)。{{cfsFileUrl}}是需要当前文件上下文的CollectionFS帮助程序,因此如果没有{{{with BioPic owner}},它将无法工作。给传记片打两次电话似乎有点多余

<template name="showBioPic">        
    {{#if BioPic owner}}
        {{#with BioPic owner}}
            <img src="{{cfsFileUrl 'size48x48gm'}}" alt="Profile Picture: {{_id}}">
        {{/with}}
    {{else}}
        <img class="showShared" src="images/default-biopic-48x48.png" alt="Default Profile Picture">
    {{/if}}
</template>


Template.showBioPic.BioPic = function (IN_ownerId) {
   return BioPicsFS.findOne( { owner: IN_ownerId });
};

{{{#如果传记片所有者}
{{{与传记片所有者一起}
{{/与}}
{{else}
{{/if}
Template.showBioPic.BioPic=函数(在所有者ID中){
返回BioPicsFS.findOne({owner:IN_ownerId});
};
以下是git/docs的集合: 块帮助程序接受一个
{{{else}
块。所以你可以做:

<template name="showBioPic">
    {{#with BioPic owner}}
        <img src="{{cfsFileUrl 'size48x48gm'}}" alt="Profile Picture: {{_id}}">
    {{else}}
        <img class="showShared" src="images/default-biopic-48x48.png" alt="Default Profile Picture">
    {{/with}}
</template>

{{{与传记片所有者一起}
{{else}
{{/与}}

这是我的破解方法,使用全局变量避免重复调用。引用世界卫生组织的话,“老兄,一定有更好的办法”

<template name="showBioPic">        
    {{#if BioPic owner}}
        {{#with foundBioPic}}
            <img src="{{cfsFileUrl 'size48x48gm'}}" alt="Profile Picture: {{_id}}">
        {{/with}}
    {{else}}
        <img class="showShared" src="images/default-biopic-48x48.png" alt="Default Profile Picture">
    {{/if}}
</template>
// Template GLOBAL
var currentBioPic = null;


Template.showBioPic.BioPic = function (IN_ownerId) {

   console.log("BioPic: IN_ownerId = " + IN_ownerId);

   currentBioPic = BioPicsFS.findOne( { owner: IN_ownerId });

   return currentBioPic;
};

Template.showBioPic.foundBioPic = function () {
   return currentBioPic;
};