简体   繁体   English

如何在Meteor.js中将图像数组应用于模板帮助器

[英]How to apply array of images to a template helper in Meteor.js

I currently am trying to apply an array of images to my template HTML. 我目前正在尝试将图像数组应用于模板HTML。

var z = [...jpg,...,jpg,...jpg];
var x = ["text","text","text"];

These arrays are stored globally in my file. 这些数组全局存储在我的文件中。

Here is my template helper function and I'm just using a sample index to see if it would be display in the HTML but it isn't working properly. 这是我的模板帮助器函数,我仅使用示例索引来查看它是否将显示在HTML中,但不能正常工作。

Template.stop.helpers({
    'thumb': function(){
      return  z[1];
    },
    'snippet': function(){
        return x[1];
    }
});

Here is my html template reference 这是我的html模板参考

 <template name="stop">  
      <tr>
        <td class="image"><img src="{{thumb}}"></td>
        <td>
         <center>    


    <h2> Do you like this product? </h2>
           <i class="fa fa-check-square-o" style=" font-size: 50px; font-size=50px; margin-top: 50; padding-top: 5px;"></i>
           <h3>{{title}}</h3>
           <h2>{{snippet}}</h2>
        </td>
      </tr>
    </template>

and here is where it's referenced in a div in my body 这是我体内的div中引用的位置

<div class="bottom">
  {{> stop}}
  </div>

I want these images displayed in a table in my HTML but I'm not even able to display one. 我希望这些图像显示在HTML的表格中,但我什至无法显示。 Any ideas? 有任何想法吗?

Code seems ok remove var keyword, maybe a duplicated on z x2? 代码似乎可以删除var关键字,也许在z x2上重复了吗?

 z = [...jpg,...,jpg,...jpg];
 x = ["text","text","text"];

if you have that array of images pointing to a /public folder add it also. 如果您有指向/public文件夹的图像数组,请同时添加它。

<td class="image"><img src="public/{{thumb}}"></td>

update 更新

if(Meteor.isClient){
      z = [...jpg,...,jpg,...jpg];
      x = ["text","text","text"];
for(var i=0;i<z.length;i++){
   console.log(z[i])
 }
  Template.stop.helpers({
    'thumb': function(){
      console.log(z[1];
      return  z[1];
    },
    'snippet': function(){
        return x[1];
    }
 });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM