SmartCollection Fruits
上的查询结果将在Meteor模板中呈现。 Python脚本不断在fruit
集合中插入文档。
集合/ fruits.js
Fruits = new Meteor.SmartCollection('fruits');
服务器/ publications.js
Meteor.publish('fruits', function(userId) {
return Fruits.find({}, {sort:{timestamp: -1}, limit: 30+1});
});
的客户机/ main.html中
<template name="fruits">
{{#each fruit}}
{{name}} {{price}}
{{/each}}
</template>
的客户机/ 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)
答案 0 :(得分:1)
我遇到了同样的问题。我试过了{{#isolate}}
然而这是无效的。相反,我在{{#constant}}
之后立即使用了{{each}}
。代码看起来像这样,效果很好:
{{#each file}}
{{#constant}}
{{filename}}
{{/constant}}
{{/each file}}
答案 1 :(得分:0)
由于Meteor在数据发生变化时修补了DOM,因此会发生闪烁。 Meteor UI应该解决这个问题,当它出来但仍然需要一段时间......
您可以使用{{#isolate}}
分隔每个块,以便只修改已更改的块。
{{#isolate}}
{{name}} {{price}}
{{/isolate}}
如果您添加了一种价格介于两种其他水果之间的新水果,这将无济于事。新的水果必须重新呈现整个列表,因为它必须在中途插入新的水果。
除非你有某种图像,否则你不应该注意到闪烁,我假设你已经遗漏了一些代码,但试着把图像放在{{#isolate}}
中。我不确定它会起作用,但它可以。