示例代码:过滤骨干集合返回模型的数组
this.books = this.getBooksFromDatabase();
this.publishedBooks = this.books.filter(function(book) {
return book.get("isPublished") === "1";
});
这里躺着的问题:
this.books.filter,返回模型的数组。我已经试过包装的阵列,因为这样的:
var publishedBooks = _(this.books.filter(function(book) {
return book.get("isPublished") === "1";
}))
所推荐的这篇文章: https://github.com/documentcloud/backbone/issues/120
,但我仍然不能运行的东西,如: publishedBooks.each(...)或 publishedBooks.get(...)
我在想什么?有没有办法将返回的数组转换为集合?
Collection#refresh已重命名为Collection#reset http://documentcloud.github.com/backbone/#Collection-reset –