简体   繁体   English

流星:实例化没有点击事件的会话

[英]Meteor: instantiate a Session without the click event

Using Meteor 0.9+. 使用流星0.9+。

Is there a way to instantiate a session as soon as the page renders? 有没有一种方法可以在页面呈现后立即实例化会话?

I have a dynamic list of names that display upon clicking a .li element using the click event. 我有一个动态的名称列表,这些名称在使用click事件单击.li元素时显示。 This is fine. 这可以。 But I would like the user now to see at least one list, ie as if they have already clicked one of the .li elements when they land on the page. 但是,我希望用户现在看到至少一个列表,即,当他们登陆页面时,好像他们已经单击了.li元素之一。

Template.nameList.events({
'click li.title': function(e) {
    e.preventDefault();
    Session.set('postId', this._id);
    var selectedId = Session.get('postId');
}
});

You could use template.created or template.rendered callback: 您可以使用template.createdtemplate.rendered回调:

Template.nameList.rendered = function() {
  Session.set('postId', this.data.someId);
};

You could also use IR onBeforeAction callback: 您还可以使用IR onBeforeAction回调:

NameListRouter = RouteController.extend({
  onBeforeAction: function() {
    Session.set('postId', this.params.someId);
  };
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM