为什么 Meteor.users.findOne({username: "test"}) returns 一个对象但是用具有相同值 returns undefined 的变量替换 "test"
Why does Meteor.users.findOne({username: "test"}) returns an object but replacing "test" with variable that has the same value returns undefined
var usr = [];
var chatUsers = Session.get("newChatUser");
for ( i in chatUsers )
{
var a = chatUsers[i];
var id = Meteor.users.findOne({ username : a });
usr.push({
uid : id._id,
name : a
});
}
当 a 为 "test" 但当我 运行
时,这里的 id 变为未定义
Meteor.users.findOne({ username : "test" })
在浏览器控制台中,它 returns 是正确的对象。我的代码有什么问题?
尝试:
Meteor.users.findOne({ username: a.trim() })
var usr = [];
var chatUsers = Session.get("newChatUser");
for ( i in chatUsers )
{
var a = chatUsers[i];
var id = Meteor.users.findOne({ username : a });
usr.push({
uid : id._id,
name : a
});
}
当 a 为 "test" 但当我 运行
时,这里的 id 变为未定义Meteor.users.findOne({ username : "test" })
在浏览器控制台中,它 returns 是正确的对象。我的代码有什么问题?
尝试:
Meteor.users.findOne({ username: a.trim() })