簡體   English   中英

使用Iron Router和Meteor加載數據

[英]Loading data using Iron Router and Meteor

這是我的困境。 我目前正在使用靜態變量將類別加載到“類別”頁面上。 一切都會加載,並且鏈接是可單擊的,但是當用戶單擊類別時。 “ categoryPage”不會加載屬於該類別的相應圖像。 這是我的代碼。

categoryPage HTML:

<template name="categoryPage">
    <div class="text-center light-container" id="home-section">
        <h1>{{categoryName}}</h1>
        <hr/>
        <div class="row">
            {{#each categoryGifs}}
                <a href="{{pathFor 'gif'}}">
                    <img class="freezeframe gifs" data-id="{{_id}}" src="{{image}}"/>
                </a>
            {{/each}}
        </div>
    </div>
</template>

categoryPage JS:

Template.categoryPage.helpers({
    // Load 16 most recent ones
    // When down arrow is click load another 16 more gifs
    'categoryName': function(){
        var category = this.params.category;
        return category;
    },
    'categoryGifs': function() {
        var category = this.params.category;
        console.log(category);
        return GifsCollection.find({category: category}, {fields: {_id: 1, image: 1, category: 1} });
    }
});

路由器JS:

Router.route('/categories', {
    name: 'categories',
    template: 'categories',
    fastRender: true
});
Router.route('/categories/:category', {
    name: 'categoryPage',
    template: 'categoryPage',
    data: function(){
        var category = this.params.category;
        return GifsCollection.find({category: category});
    },
    fastRender: true
});

在“ categoryGifs”中:function(),更改

    var category = this.params.category;

與:

    var category = Router.current().params.category;

這是工作代碼:

http://meteorpad.com/pad/AdRS8mfyHsZjA2Rvp/排行榜

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM