【发布时间】:2015-06-10 10:36:40
【问题描述】:
我正在创建一个聊天应用程序。如果我检查当前聊天的消息计数等于 0,我希望我可以添加一个新的“你好”消息(问题 #1)。我也有一本字典作为翻译的集合。但是 t() 返回 EN 变体(问题 #2)
t = function(text) {
var res = Dictionary.findOne({o:text});
return res && res.t || text;
}
Meteor.startup(function () {
Deps.autorun(function () {
Meteor.subscribe('dictionary', Session.get('lang'), function(){
Session.set('dictionaryReady', true);
});
Meteor.subscribe('chats', Session.get('domain'), function(){
if (chatCurrent(Meteor.userId(), Session.get('domain')).count()===0 //true, even is not actually [problem_#1]
&& Session.get('dictionaryReady') //true, but next function t() doesn't work properly [problem #2]
) {
var mudata = Session.get('my_manager') ? udata(Session.get('my_manager'), Session.get('domain')) : null,
hello = mudata && mudata.hello || t('Hello! How I can help you?'),
name = mudata && mudata.name || t('Anna');
Meteor.call('create_message', {chat: Meteor.userId(), to: Meteor.userId(), text: hello, name: name, from: Session.get('my_manager'), domain: Session.get('domain'), last_manager: Session.get('my_manager')});
});
});
});
每次刚加载页面时都会出现问题 #1 和问题 #2。因此,当我刷新页面时,我会在默认 EN 语言环境中收到另一条“hello message”。
【问题讨论】:
标签: meteor