我正在尝试使用backbone.js的Todos example,但是当我运行保存时,toggleAllComplete函数并没有遍历集合。但是,当我警告标题时,它会遍历整个集合。
toggleAllComplete: function () {
var done = this.allCheckbox.checked;
Todos.each(function (todo) {
/* this doesn't iterate over the collection */
// todo.save({'done': done});
/* this does */
alert(todo.get('title'));
});
}为什么?
我也尝试过使用_.each(Todos.models, function(todo) {,但同样的问题仍然存在。当我在chrome中使用开发人员工具时,我看到了一个未捕获的类型错误:在line localstorage.js中的这一行中,将循环结构转换为JSON
this.localStorage().setItem(this.name+"-"+model.id, JSON.stringify(model));发布于 2013-02-27 08:15:09
如果有错误保存,那么它可能会阻止每个模型检查每个模型。当你做一个警告,没有错误,所以它让每个人做自己的工作。
您可以尝试在save方法中抛出一些回调函数,看看这是否有助于调试。
todo.save({'done': done}, {
success: function() { console.log(["success", arguments]); }
error: function() { console.log(["error", arguments]); }
});https://stackoverflow.com/questions/14844154
复制相似问题