使用{{this}}作为Meteor中助手的参数

lil*_*i42 0 javascript meteor

我在Meteor中有以下辅助函数:

sourceArray : function () {

        sources = [];

            for (var i = 0; i < images.length; i++) {
                if (!isInArray(images[i].source, sources)) {
                    sources.push(images[i].source);
                }
            }

        return sources; 
      }
Run Code Online (Sandbox Code Playgroud)

我也有这个辅助功能:

imageTitle : function (source) {
          var index = sources.indexOf(source);
          return images[index].title;
      }
Run Code Online (Sandbox Code Playgroud)

在我的HTML中,我想使用这样的帮助器,{{this}}作为参数传递:

<div class="row">
                {{#each sourceArray}}
                <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
                    <a href="#" class="thumbnail">
                    <img class="img-responsive" src={{this}}>
                    </a>
                    <!-- THIS IS THE IMPORTANT BIT -->
                    {{imageTitle {{this}} }}

                </div>
                {{/each}}
        </div>
Run Code Online (Sandbox Code Playgroud)

这样做,我收到以下错误:

Errors prevented startup:

 While building the application:
 art.html:55: Expected identifier, number, string, boolean, or null
 ...                <h3>{{imageTitle {{this}} }}</h3>
 ...
 ^
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能解决这个问题?

Sir*_*son 5

我现在正在移动,但我会给你一个巨大的提示.在each块的内部,您不需要传递this给帮助程序.你可以this在JS中调用它,它将引用你当前试图传入的相同内容.