2015-02-12 33 views
0

我使用流星創建了一個投資組合,併成功地循環了數據庫中的投資組合項目(使用燈具創建)。我遇到問題,試圖按一個項目並轉到它的特定頁面。我確信這很簡單,但我對流星很新。流星路線到個人頁面

我的結構如下:

收集:

PortfolioItems = new Mongo.Collection('portfolioItems'); 

公開:

Meteor.publish('portfolioItems', function() { 
    return PortfolioItems.find(); 
}); 

組合頁模板:

<template name="portfolio"> 
<h1>Portfolio</h1> 
<hr> 
{{#each portfolioItems}} 
    {{> portfolioItem}} 
{{/each}} 

<a href="{{pathFor 'home'}}">Go Back Home</a> 
</template> 

組合頁面模板Helpe R:

Template.portfolio.helpers({ 
    portfolioItems: function() { 
     return PortfolioItems.find({}); 
    } 
}); 

組合項模板:

<template name="portfolioItem"> 
<h1>{{title}}</h1> 
</template> 

最後我的路線:

Router.configure({ 
    layoutTemplate: 'layout', 
    loadingTemplate: 'loading', 
    notFoundTemplate: 'notFound' 
}); 


Router.route('/', function() { 
    this.render('home'); 
}, { 
    name: 'home' 
}); 

Router.route('/about', function() { 
    this.render('about'); 
}); 

Router.route('/portfolio', function() { 
    this.render('portfolio'); 
}, { 
    name: 'portfolio', 
    waitOn: function() { 
     return Meteor.subscribe('portfolioItems'); 
    } 
}); 

回答

1

首先創建的路線。

Router.map(function() { 
    this.route('portfolioItem', { 
    path: '/portfolioIndividual/:_id', 
     waitOn: function(){ 
    return Meteor.subscribe('portfolioItems'); 
    }, 
    data: function(){ 
    if(this.ready()){ 
     return PortfolioItems.findOne({_id: this.params._id}); 
    }else{ 
     this.render('loading') 
    }  
    } 
    }); 
}); 

HTML:

<template name="portfolio"> 
{{#each portfolioItems}} 
    <a href="/portfolioIndividual/this._id">Take a look at this awesome photo</a> 
{{/each}} 
</template> 

<template name="portfolioItem"> 
    <!-- portfolio item content --> 
</template> 
+0

如何{{#each portfolioItems}}在這個工作 \t {{> portfolioItem}} {{/每}} – Dileet 2015-02-12 02:04:27

+0

的網址最終被本地主機: 3000 /組合/ this._id – Dileet 2015-02-13 04:31:44