0
我有一個定義發佈/訂閱行爲的文件,但它只能運行10次。當它不起作用時,查詢返回爲未定義。我可以在chrome的控制檯中執行成功的查詢,所以在查詢觸發後它必須加載。流星發佈/訂閱競賽條件
[項目根] /lib/site.js
Articles = new Mongo.Collection("articles");
Authors = new Mongo.Collection("authors");
if (Meteor.isServer) {
Meteor.publish("articles", function() {
return Articles.find();
});
Meteor.publish("authors", function() {
return Authors.find();
});
}
if (Meteor.isClient) {
Meteor.subscribe("articles");
Meteor.subscribe("authors");
}
[項目根] /client/modules/articleAdHelper.js
var getArticle = function (id) {
var article = Articles.findOne({articleID: id});
var author = Authors.findOne({_id: article.authorID});
article.authorName = author.authorName;
article.authorPageUrl = author.authorPageUrl;
article.authorAvatar = author.authorAvatar;
article.articlepublishTimePassedMessage = getPublishDateMessage(article.articlePublishDatetime);
return article;
};
var getAdUnit = function (unitKey) {
for (var i = 0; i < unitKey.length; i++) {
unitKey[i] = getArticle(unitKey[i]);
}
return {
m: [
unitKey[0],
unitKey[1]
],
h: [
unitKey[2],
unitKey[3],
unitKey[4],
unitKey[5]
]
}
};
var articleID = "testarticle";
var adUnitObj = getAdUnit([
"testarticle",
"claudeArticle",
"emusk",
"claudeArticle",
"testarticle",
"adCreatePageTest"
]);
Template.frontPageArticleAdUnit.helpers(adUnitObj);