【发布时间】:2016-07-20 22:44:31
【问题描述】:
我研究 Backbone n 下划线。
有人帮助我。
我不知道模型是未定义的 _.each()。
var todos = new Backbone.Collection();
todos.add([
{ title: 'go to Belgium.', completed: false },
{ title: 'go to China.', completed: false },
{ title: 'go to Austria.', completed: true }
]);
// iterate over models in the collection
todos.forEach(function(model){
console.log(model.get('title'));
});
// Above logs:
// go to Belgium.
// go to China.
// go to Austria.
为什么模型未定义???
/*underscoreJS model is undefined...*/
_.each(todos, function (model) {
console.log(model.get('title'));
});
【问题讨论】:
-
Backbone 有
_.each方法的代理,你必须在你的情况下使用它:todos.each(function(todo) {...})
标签: javascript foreach underscore.js each