首先,当然是一如既往地看官方文档的解释. Collections are ordered sets of models. 翻译: Collections是models的一个集合. 关于book和bookshelf的例子 var Book = Backbone.Model.extend({ defaults: { title: null }, initialize: function() { console.log("hi, you create me!"); } }); var Boo…
写了近半个月的backbone.js代码,从一开始的todo到现在做仿微信的网页聊天,其中最大的困惑就在于如何处理比较复杂的Model,其内嵌了一个或者多个Collections. 假设我们有一个Person的Model,一个Person会有多个工作,那么我们将jobs这个属性设置为一个Collection: 初始化代码如下: var Job = Backbone.Model.extend({ }); var Jobs = Backbone.Collection.extend({ model:J…
首先,我们看一下官方文档中对Model的解释(或者说定义): Models are the heart of any JavaScript application, containing the interactive data as well as a large part of the logic surrounding it: conversions, validations, computed properties, and access control. You extend Back…
千呼万唤始出来,终于到最后一个要点View了.照旧,先来一睹官方文档: Backbone views are almost more convention than they are code - they don't determine anything about your HTML or CSS for you, and can be used with any JavaScript templating library. The general idea is to organize y…