【问题标题】:Unable to save object using BackboneJS and the Indexeddb adatper无法使用 Backbone JS 和 Indexeddb 适配器保存对象
【发布时间】:2014-06-21 19:44:15
【问题描述】:

我正在使用BackboneJS 创建一个网络应用程序,它使用IndexedDb adapter 保存数据。我无法持久化对象,因为调用 save() 方法时会引发异常,即使对于非常简单的对象也是如此。

var page = new Page();
page.set({
   'title': 'New page',
   'number': 1
});
page.save()

...导致错误消息(在 Chrome 中)。

异常消息:无法在“IDBObjectStore”上执行“添加”:An 无法克隆对象。

【问题讨论】:

    标签: javascript backbone.js indexeddb


    【解决方案1】:

    使用BackboneJSIndexedDB adapter 创建新对象时,您需要将数据传递给save 方法(而不是之前设置)。

    var page = new Page();
    page.save(
        {
            'title': 'New page',
            'number': 1
        },
        {
            success: function(){
                // Object saved
            },
            error: function(){
               // An error occurred when saving
            }
        }
    );
    

    该项目的单元测试是关于如何使用 API 的一个非常好的示例来源:https://github.com/superfeedr/indexeddb-backbonejs-adapter/blob/master/tests/test.js

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-08
      • 1970-01-01
      • 1970-01-01
      • 2012-08-18
      • 2012-12-18
      • 1970-01-01
      • 2012-12-14
      • 2018-04-26
      相关资源
      最近更新 更多