![](/img/trans.png)
[英]How to change a session value after a click event, so that a page refresh does not reset the session on Meteor
[英]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.created
或template.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.