当我从前端调用Collection.update(允许方法调用)时,更新确实可以正常工作,但是抛出了以下异常(在Chrome的JS控制台中,而不是在服务器中)。虽然更新发生了,但是连接到同一个集合的其他客户端在刷新浏览器之前看不到更新 - 我怀疑是因为异常。
知道可能导致这种情况的原因吗?
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>
这里是'list_item'点击的事件处理程序:
Template.list_item.events = {
'click .checklistitem' : function(ev) {
this.checked = !this.checked;
var updateItem = {};
updateItem['items.'+this.index+'.checked'] = this.checked;
console.log("The error happens here");
Lists.update({_id: this._id}, {$set:updateItem}, {multi:false} , function(err) {
console.log("In callback, after the error");
});
}
}
整个事情可以在http://checkadoo.com(它是我的基于Tornado的Python应用程序的端口)
答案 0 :(得分:0)
我发现这通常是重复ID的问题。 @Harel的问题不包括实际呈现集合的代码,因此我们无法分辨出他的问题的根本原因,但是注释中提供的@Drew的repro抛出了这个错误,因为它渲染了一个包含的对象数组重复'_id'值。
我已经整理了@Drew's repro的工作版本: https://github.com/alanning/meteor-buggy-fix
关键修复是确保插入的饮品没有重复的'_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}});
}
});