0

所以目前我所有的收藏和模型都来自服务器休息 api 并且工作正常。

我使用最新的 Backbone.localStorage.js

现在我想要几个模型只保存到 localStorage。我不确定我需要在这里做什么,这就是我只想使用 localstorage 的模型和集合。

class Upload extends Backbone.Model
class Uploads extends Backbone.Collection
    localStorage: new Backbone.LocalStorage 'uploads'
    initialize: =>
        @model = Upload
    sync:(method, model, options) =>
        return Backbone.localSync.call(model, method, model, options)

所以做完之后 ny 集合总是空的

model = new Upload(name:foo)
collection = new Uploads
collection.add(model)
console.log collection shows it has one model here, but logging on the sync overide its empty again
4

1 回答 1

0

不确定如何让集合同步,但您可以调用 model.save() 将其添加到 localStorage。只需先将“localStorage: new Backbone.LocalStorage 'uploads'”行添加到您的上传模型。

于 2013-09-19T18:50:15.923 回答