簡體   English   中英

流星:實例化沒有點擊事件的會話

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

使用流星0.9+。

有沒有一種方法可以在頁面呈現后立即實例化會話?

我有一個動態的名稱列表,這些名稱在使用click事件單擊.li元素時顯示。 這可以。 但是,我希望用戶現在看到至少一個列表,即,當他們登陸頁面時,好像他們已經單擊了.li元素之一。

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

您可以使用template.createdtemplate.rendered回調:

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

您還可以使用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