在路由器和集合之间传递id,Meteor

时间:2015-02-05 23:25:35

标签: javascript meteor iron-router

我正在尝试在我的路由器中使用Session.set(),在我的架构中使用Session.get() autoValue,但在我的架构范围内未定义Session.get()。如何将当前id的值(因为它附加到我的网址末尾)传递给我的架构中的autoValue

    //collections/singleDetails.js

    singleDetails = new Meteor.Collection('singleDetails');

    singleDetails.attachSchema(new SimpleSchema({

        location: {
            type: String,
            label: 'location',
            max: 200,
            optional: true
        },

        number: {
            type: Number,
            label: 'number of attendees',
            max: 2000,
            optional: true
        },

        occasion: {
            type: String,
            label: 'occasion for speech'
        },

        speakerId: {
            type: String,
            autoValue: function(){
                Session.get('pathId');
            }
        }

    }));

这是路由器

    //client/views/singleDetails.js

    Router.route('singleDetails', {
        path: '/speakers/singleDetails/:_id',
        template: 'singleDetails',
        data: function(){
            return Speakers.findOne({_id: this.params._id});
        },
        onBeforeAction: function(){
            console.log(this.params._id);
            Session.set('pathId', this.params._id);
            this.next();
        }
    });

    Template.singleDetails.helpers({

        singleDetails: function(){
            return singleDetails.find({});
        }
    });

0 个答案:

没有答案