BackboneJS教學
BackboneJS環境設置
BackboneJS應用
BackboneJS事件
BackboneJS事件on
BackboneJS事件off
BackboneJS事件trigger
BackboneJS事件once
BackboneJS事件listenTo
BackboneJS事件stopListening
BackboneJS事件listenToOnce
BackboneJS模型
BackboneJS Model.extend()方法
BackboneJS Model.initialize()方法
BackboneJS Model.get()方法
BackboneJS Model.set()方法
BackboneJS model.escape()方法
BackboneJS model.has()方法
BackboneJS model.unset()方法
BackboneJS model.clear()方法
BackboneJS model.id屬性
BackboneJS model.idAttribute屬性
BackboneJS model.cid屬性
BackboneJS model.attributes屬性
BackboneJS model.changed
BackboneJS model.defaults
BackboneJS model.toJSON()方法
BackboneJS model.sync()方法
BackboneJS model.fetch()方法
BackboneJS model.save()方法
BackboneJS model.destroy()方法
BackboneJS model.validate()方法
BackboneJS model.validationError
BackboneJS model.isValid()方法
BackboneJS model.url()方法
BackboneJS model.urlRoot()方法
BackboneJS model.parse()方法
BackboneJS model.clone()方法
BackboneJS model.hasChanged()方法
BackboneJS model.isNew()方法
BackboneJS model.changedAttributes()方法
BackboneJS model.previous()方法
BackboneJS model.previousAttributes()方法
BackboneJS集合
BackboneJS Collection.extend()方法
BackboneJS Collection.model
BackboneJS 集合初始化
BackboneJS collection.models
BackboneJS collection.toJSON()方法
BackboneJS collection.sync()方法
BackboneJS collection.add()方法
BackboneJS collection.remove()方法
BackboneJS collection.reset()方法
BackboneJS collection.set()方法
BackboneJS collection.get(id)方法
BackboneJS collection.at()方法
BackboneJS collection.push()方法
BackboneJS collection.pop()方法
BackboneJS collection.unshift()方法
BackboneJS collection.shift()方法
BackboneJS collection.slice()方法
BackboneJS collection.length
BackboneJS collection.comparator屬性
BackboneJS collection.sort()函數
BackboneJS collection.pluck()方法
BackboneJS collection.where()方法
BackboneJS collection.findWhere()方法
BackboneJS collection.url()方法
BackboneJS collection.parse()方法
BackboneJS collection.clone()方法
BackboneJS collection.fetch()方法
BackboneJS collection.create()方法
BackboneJS路由
BackboneJS router.execute()方法
BackboneJS router.routes
BackboneJS Router初始化
BackboneJS router.navigate()方法
BackboneJS router.route()方法
BackboneJS Backbone.history.start()方法
BackboneJS同步
BackboneJS .sync()方法
BackboneJS Backbone.emulateHTTP
BackboneJS Backbone.emulateJSON
BackboneJS視圖
Backbone.View.extend()方法
BackboneJS視圖初始化
BackboneJS view.el
BackboneJS view.$el
BackboneJS view.setElement()方法
BackboneJS view.attributes
BackboneJS view.$(selector)方法
BackboneJS view.template(data)方法

BackboneJS model.save()方法

它通過委派sync() 方法讀取和每次保存模型時調用Backbone便會保存模型的數據。

語法

model.save(attributes,options)

參數:

  • attributes: 它定義了一個模型的屬性。
  • options: 它接受參數,如id, name 等它們用於一個模型。

示例

Model Example

輸出

讓我們進行以下步驟來看看上面的代碼工作:

  • 保存上述代碼在文件save.html

  • 打開瀏覽器這個HTML文件。