SmartCollection Fruits
的查询结果在 Meteor 模板中呈现。一个 Python 脚本不断地在 fruit
集合中插入文档。
collections/fruits.js
Fruits = new Meteor.SmartCollection('fruits');
server/publications.js
Meteor.publish('fruits', function(userId) {
return Fruits.find({}, {sort:{timestamp: -1}, limit: 30+1});
});
client/main.html
<template name="fruits">
{{#each fruit}}
{{name}} {{price}}
{{/each}}
</template>
client/main.js
Template.fruits.fruit = function() {
return Fruits.find({}, {sort:{price: -1}})
}
问题 Template.fruits
的输出似乎经常闪烁,大概是在更新集合的本地副本时。我们怎样才能避免闪烁?
使用 Meteor v6.6.3 和 smart-collection v0.3.23
使用 Python 插入文档
for date, row in fruits.T.iterkv():
docExist = db.fruits.find({'timestamp': row['timestamp']})
if docExist.count() == 0:
db.fruits.insert(data)
最佳答案
我遇到了同样的问题。我尝试了 {{#isolate}}
但是那是无效的。相反,我在 {{each}}
之后使用了 {{#constant}}
。代码看起来像这样并且运行良好:
{{#each file}}
{{#constant}}
{{filename}}
{{/constant}}
{{/each file}}
关于javascript - 使用 Meteor 的 SmartCollection 时的闪烁效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20298478/