使用 Meteor 0.9+。
有没有办法在页面呈现后立即实例化 session ?
我有一个动态名称列表,在使用 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);
};
});
关于javascript - Meteor:实例化一个Session,没有点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26607360/