我的流星目录由 2 个文件组成:
社会.js:
Messages = new Meteor.Collection("messages");
if (Meteor.isServer) {
}
if (Meteor.isClient) {
Template.temple.messages = function() {
return Messages.find();
};
Meteor.startup(function () {
console.log('console startup: ' + Messages.find().count());
});
console.log('console normal: ' + Messages.find().count());
var ali = function() {
console.log('console normal: ' + Messages.find().count());
};
setTimeout(function() {
console.log('console normal: ' + Messages.find().count());
}, 2000);
// The callback function is not called on the following line:
Meteor.subscribe('messages',function(){alert('ALERT!');});
}
社会.html:
<head>
<title>naber</title>
</head>
<body>
{{> temple}}
</body>
<template name = "temple">
{{#each messages}}
{{message}} <br />
{{/each}}
</template>
该集合仅在经过一段时间后才完全加载。如果我环绕一个setTimeout
. 在数据库真正完全可用后,我能做些什么来确保我的功能被执行?