我在客户端上运行的咖啡脚本中有一个模板函数:
Template.leftNav.starred = () ->
user = Meteor.user()
if ! user
return
else
starredPages = user.profile.starredPages
starred = Entries.find({ _id :{in: starredPages}}).fetch()
Meteor.user()
返回
Object {_id: "AHSwfYgeGmur9oHzu", profile: Object}
_id: "AHSwfYgeGmur9oHzu"
profile: Object
starredPages: Array[4]
0: "asdasdasdasdasd"
1: "abc123"
2: "blobby"
3: "bxSbMgszYxbCqDonF"
并Meteor Entries.find({})
返回:
Entries
Meteor.Collection {_makeNewID: function, _transform: null, _manager: Meteor._LivedataConnection, _collection: LocalCollection, _name: "entries"…}
_collection: LocalCollection
_savedOriginals: null
docs: Object
Wkxxpapm8bbiq59ig:
_id: "M3vDJNMZJjBDfrc7D"
bxSbMgszYxbCqDonF:
_id: "bxSbMgszYxbCqDonF"
执行模板函数中的代码:
starredPages = user.profile.starredPages
starred = Entries.find({ _id :{in: starredPages}}).fetch()
starred
即使bxSbMgszYxbCqDonF
starredPages 数组中的_id
值与Entries.docs
集合数组中的值匹配,也会作为空白数组返回。
为什么会这样以及如何让它返回starredPages
数组和_id
's 之间的匹配项?