Node.js 更新集合时Meteor.flush中的Meteor异常会破坏客户端之间的反应性
当我从前端调用Collection.update(允许方法调用)时,更新工作正常,但会引发下面的异常(在Chrome的JS控制台中,而不是在服务器中)。虽然发生了更新,但连接到同一集合的其他客户端在刷新浏览器之前看不到更新-我怀疑是因为异常 知道这是什么原因吗Node.js 更新集合时Meteor.flush中的Meteor异常会破坏客户端之间的反应性,node.js,meteor,Node.js,Meteor,当我从前端调用Collection.update(允许方法调用)时,更新工作正常,但会引发下面的异常(在Chrome的JS控制台中,而不是在服务器中)。虽然发生了更新,但连接到同一集合的其他客户端在刷新浏览器之前看不到更新-我怀疑是因为异常 知道这是什么原因吗 Exception from Meteor.flush: Error: Can't create second landmark in same branch at Object.Spark.createLandmark (htt
Exception from Meteor.flush: Error: Can't create second landmark in same branch
at Object.Spark.createLandmark (http://checkadoo.com/packages/spark/spark.js?8b4e0abcbf865e6ad778592160ec3b3401d7abd2:1085:13)
at http://checkadoo.com/packages/templating/deftemplate.js?7f4bb363e9e340dbaaea8d74ac670af40ac82d0a:115:26
at Object.Spark.labelBranch (http://checkadoo.com/packages/spark/spark.js?8b4e0abcbf865e6ad778592160ec3b3401d7abd2:1030:14)
at Object.partial [as list_item] (http://checkadoo.com/packages/templating/deftemplate.js?7f4bb363e9e340dbaaea8d74ac670af40ac82d0a:114:24)
at http://checkadoo.com/packages/handlebars/evaluate.js?ab265dbab665c32cfd7ec343166437f2e03f1a54:349:48
at Object.Spark.labelBranch (http://checkadoo.com/packages/spark/spark.js?8b4e0abcbf865e6ad778592160ec3b3401d7abd2:1030:14)
at branch (http://checkadoo.com/packages/handlebars/evaluate.js?ab265dbab665c32cfd7ec343166437f2e03f1a54:308:20)
at http://checkadoo.com/packages/handlebars/evaluate.js?ab265dbab665c32cfd7ec343166437f2e03f1a54:348:20
at Array.forEach (native)
at Function._.each._.forEach (http://checkadoo.com/packages/underscore/underscore.js?772b2587aa2fa345fb760eff9ebe5acd97937243:76:11)
编辑2
如果在控制台中运行更新调用,也会发生此错误。它发生在更新的第一次运行时,但在与之连接的任何其他浏览器上,反应性都会中断
编辑
以下是触发更新的可单击项的模板:
<template name="list_item">
<li class="checklistitemli">
<div class="{{checkbox_class}}" id="clitem_{{index}}">
<input type="checkbox" name="item_checked" value="1" id="clcheck_{{index}}" class="checklist_item_check" {{checkbox_ticked}}> {{title}}
</div>
</li>
</template>
整个东西都可以在(我的一个基于Tornado的Python应用程序的端口)上找到。我发现这通常是一个重复ID的问题@Harel的问题不包括实际呈现集合的代码,因此我们无法说出问题的根本原因,但注释中提供的@Drew的repu抛出了此错误,因为它呈现的对象数组具有重复的“\u id”值 我制作了一个@Drew's Repo的工作版本: 关键修复是确保插入的饮料项目没有重复的“\u id”字段:
Template.drink_from_menu.events({
'click .buy_drink': function () {
var drink = {name: this.name, price: this.price};
console.log("this = ", this);
// using 'this' doesn't work because it already has a '_id' field and
// you would be trying to render multiple drinks with the same id
// which causes Spark to throw the "Can't create second landmark
// in same branch" error
//Tabs.update({_id:Session.get('tabId')}, {$push: {ordered_drinks: this}});
// either ensure that the objects you want Spark to render have a
// unique id or leave off the _id completely and let Spark do it for you
Tabs.update({_id:Session.get('tabId')}, {$push: {ordered_drinks: drink}});
}
});
也许可以向我们展示你是如何呈现正在更新的收藏的?我认为问题不在于没有关闭
,而在于我对这个问题的模糊理解(与此相关)我想,如果不看到调用list\u item
本身的上下文,就很难对此有所帮助。我也遇到了这个问题。这里展示了一个简单的应用程序:要复制,请在控制台上创建一个带有选项卡的选项卡。插入({owner:“foo”})
然后访问localhost:3000/Tabs/:id
然后单击“买一个”按钮EZ刚刚注意到了该操作的名称-这是一个小世界Harel:D
Template.drink_from_menu.events({
'click .buy_drink': function () {
var drink = {name: this.name, price: this.price};
console.log("this = ", this);
// using 'this' doesn't work because it already has a '_id' field and
// you would be trying to render multiple drinks with the same id
// which causes Spark to throw the "Can't create second landmark
// in same branch" error
//Tabs.update({_id:Session.get('tabId')}, {$push: {ordered_drinks: this}});
// either ensure that the objects you want Spark to render have a
// unique id or leave off the _id completely and let Spark do it for you
Tabs.update({_id:Session.get('tabId')}, {$push: {ordered_drinks: drink}});
}
});