2

我刚刚更新到 Meteor 1.0 和 Iron-Router 的最新版本。

无论出于何种原因,当我将数据传递给仅包含单个文档的模板时,它就可以工作。但是当我尝试将多个文档传递给模板时,我得到一个空白屏幕。

//galleryRoute.js

Router.route('/:section', function() {
    this.layout('Gallery', {
        data: function() { 
            var data =  { photos: photos.find({ path: { $regex: '/'+this.params.section +'/' } }) };
            return data;
        }
    });
});

<template name="Gallery">
    <div class="container">
        {{#each photos}}    
            <div class="section-photo" style="background:url({{path}}) no-repeat center center; width:175px; height:175px; background-size:cover;"></div>
        {{/each}}
    </div>
</template>

想知道是否有人对为什么会这样有任何想法?

4

1 回答 1

-1

在您的数据函数中,您正在访问this.params.section. 但是,thisis 是指您当前的范围,而不是路由,因此this.params将是未定义的。尝试做这样的事情:

//galleryRoute.js

Router.route('/:section', function() {
    var route = this;
    this.layout('Gallery', {
        data: function() { 
            var data =  { photos: photos.find({ path: { $regex: '/'+route.params.section +'/' } }) };
            return data;
        }
    });
});
于 2014-11-02T05:56:12.647 回答