简体   繁体   English

img src中的流星模板不起作用

[英]Meteor template in img src not working

I am aware that images are to be kept in the public folder and the public folder is not to be referenced. 我知道图像将保留在公用文件夹中,并且不会引用公用文件夹。 Here is what I'm working with and I cannot for the life of me figure out what bug is causing the images to not load. 这是我正在使用的工具,我一生无法确定导致图像无法加载的错误。

HTML: HTML:

<body>
{{>carousel}}
</body>
<template name="carousel">

    <div class="carousel">
        <span class="back">
            <a href="#">Back</a>
        </span>
        {{>carouselImages}}
        <span class="forward">
            <a href="#">Forward</a>
        </span>
    </div>
</template>

<template name="carouselImages">
    <img src="{{slide}}" height="200px" width="200px">
</template>

JavaScript: JavaScript:

slideNumber = 0;



if (Meteor.isClient) {
        Template.carousel.events({
                'click .back': function(){
                    if (slideNumber == 0){
                        slideNumber = 4;
                    } else {
                        slideNumber++;
                    }
                },
                'click .forward': function(){
                    if (slideNumber == 4){
                        slideNumber = 0;
                    } else {
                        slideNumber--;
                    }
                }
        });

        Template.carousel.helpers({
            slide: function(slideNumber){
                switch(slideNumber) {
                    case 0:
                            return "21.png";
                            break;
                    case 1:
                            return "bj2.png";
                            break;
                    case 2:
                            return "vp.png";
                            break;
                    case 3:
                            return "vp2.png";
                            break;
                    case 4:
                            return "vp3b.png";
                            break;
                }
            }
        });
}

if (Meteor.isServer) {

}

You are trying to refer to a global variable ( slideNumber ) but provide a local overload ( slide: function(slideNumber) ), and you are not providing any arguments to slide in your template. 您试图引用一个全局变量( slideNumber ),但是提供了一个局部重载( slide: function(slideNumber) ),并且您没有提供任何要在模板中slide参数。 Either remove the local argument (see below), or provide is somehow as argument. 要么删除局部参数(请参见下文),要么以某种方式提供参数。

Template.carouselImages.helpers({
    slide: function() {
        switch(slideNumber) {
           ...
        }
    }
});

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

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