我需要了解会话。实际上,我们使用session.set(key,value)和session.get(key)等默认会话。在此默认会话将被清除某些情况下,像刷新等在Meteor JS中使用会话问题?
首先我使用meteor add u2622:persistent-session
此PKG的Pkg.Use得到一个错误,即“未捕获的错误:流星目前不支持超过对象ID对象为其他IDS” 。
为了克服这些问题,使用amplify Sessions
。但一个样品没有使用放大会话如下所示代码:
JS代码:
Messages = new Meteor.Collection("messages");
if (Meteor.isClient) {
var AmplifiedSession = _.extend({}, Session, {
keys: _.object(_.map(amplify.store(), function (value, key) {
return [key, JSON.stringify(value)];
})),
set: function (key, value) {
Session.set.apply(this, arguments);
amplify.store(key, value);
}
});
// counter starts at 0
Session.setDefault('counter', 0);
AmplifiedSession.set('no', 1);
Template.hello.helpers({
counter: function() {
return Session.get('counter');
}
});
Template.hello.helpers({
no: function() {
return AmplifiedSession.get('no');
}
});
Template.hello.events({
'click button': function() {
// increment the counter when button is clicked
console.log("Btn Clicked");
Session.set('counter', Session.get('counter') + 1);
AmplifiedSession.set('no',AmplifiedSession.get('no') + 1);
}
});
}
if (Meteor.isServer) {
Meteor.startup(function() {
// code to run on server at startup
});
}
即使不working.amplify会议也在Refresh.I的时间清除没有得到这方面有任何想法所以请告诉我该怎么做。
在此先感谢。
我没有使用这个PKG一个样本工作正常,但试图在我的项目中使用得到的错误,即“未捕获错误:流星目前不支持超过对象ID对象为其他IDS”。所以,尝试另一个即” .amplify会议” @ Meteorpoly – user2344293 2015-02-09 07:13:14