有人可以向我解释一下吗:如果我从浏览器控制台中的集合中获取数据,它可以正常工作,但是在呈现模板(使用相同集合)的同时,它会抛出异常作为查询结果为空。我究竟做错了什么?
Hubs = new Meteor.Collection("hubs");
Meteor.subscribe("hubs");
Template.thread.posts = function() {
var hubName = 'foo',
thread = Session.get("currentThread"),
hub = Hubs.find({ name: hubName }).fetch()[0];
//throws: "Uncaught TypeError: Cannot read property 'threads' of undefined "
return hub.threads[thread].posts;
}
//this being executed in browser's console yeilds an object:
Hubs.find({name: 'foo'}).fetch()[0]
不过,使用相同集合的其他模板工作正常