我在 Meteor 中实现cast.js,并且在使用 Iron Router 单击缩略图后尝试渲染更大的照片,但是我无法渲染正确的路径。缩略图渲染得很好,但是当点击照片时,我得到一个错误No route found for path:
。
我用来渲染每张缩略图的模板是
var renderTemplate = function(obj){
return "<a href='{{pathFor photo}}'><img class='img-rounded' src='" + obj.picture + "'></a>"
};
Template.userPhotos.rendered = function(){
var el = this.find('#cast');
var mycast = cast(el);
mycast.draw(renderTemplate);
this.handle = Meteor.autorun(function(){
var picture = Photos.find().fetch();
mycast
.data(picture , '_id')
.dynamic(150, 150, 10, 10);
});
}
并且放在cast
这个模板的id里面
<template name="userPhotos">
<div class="container">
<div class="photos">
<div id='cast'></div>
</div>
</div>
</template>
问题来自呈现的 href。我正在尝试传递照片_id
并在下面的模板中渲染一张更大的照片,这在 mongoDB 中称为“源”。
<template name="photo">
<div class="well">
<img class="img-rounded" src="{{source}}">
</div>
</template>
目前,我的路由器设置如下:
this.route('photo', {
path: '/photo/:_id',
waitOn: function() {
return [
Meteor.subscribe('picture', this.params._id),
];
},
data: function() { return Photos.findOne(this.params._id); }
});
单击照片后,它会将我发送到此路径并引发此错误Oh no! No route found for path: "/%7B%7BpathFor"
。%7B 是 URL 的代名词,{
因此当模板作为字符串传递时,它看起来像把手或 Iron Router 并没有翻译模板。
关于如何改进此代码的任何想法?
提前致谢!