【问题标题】:Emberjs - Two custom adapterEmberjs - 两个自定义适配器
【发布时间】:2014-06-05 10:29:51
【问题描述】:

我正在开发一个需要使用 indexedDB 离线存储一些信息的应用程序,但是对于 Safari,它不可用(还),所以我需要使用 webSQL。

我已经为 indexedDB 使用了this 适配器,为不支持 indexedDB 的浏览器使用了enter link description here polyfill。

不幸的是,我在使用 Shim 时遇到了一些重大问题,例如,在 iOS Safari 和 Safari 上,当我的应用程序需要从数据库中获取一些数据以查看它是否存在时,它会返回错误。

喜欢这个和那个:

throwDOMException@http://localhost/Dev/Websites/myWebsite/js/libs/IndexedDBShim.js:40:16

Error: Assertion Failed: 0: The operation failed because the requested database object could not be found. For example, an object store did not exist but was being opened

这是由于他们使用某种 hack 来返回一些值,甚至在 polyfill 中他们这样说:

// The IndexedDB Specification needs us to return an Object Store immediatly, but WebSQL does not create and return the store immediatly // Hence, this can technically be unusable, and we hack around it, by setting the ready value to false

所以我的问题是,使用 indexedDB 适配器,我可以为 webSQL 并行添加另一个适配器吗?

【问题讨论】:

    标签: ember.js ember-data indexeddb web-sql


    【解决方案1】:

    我认为您最好的选择是在运行时选择正确的适配器(这就是您所说的并行吗?)。应该就这么简单:

    var App = Ember.Application.create();
    App.deferReadiness();
    
    if (window.indexedDB) {
        App.ApplicationAdapter = IndexedDBAdapter;
    } else {
        App.ApplicationAdapter = WebSQLAdapter;
    }
    
    App.advanceReadiness();
    

    【讨论】:

    • 这正是我所需要的!但是我在网上只能找到一个websql的适配器,不知道有没有真的更新了?
    • 不幸的是,Ember-Data 的大多数适配器并没有真正经常更新。它们中的大多数是创建然后被遗忘的。我的建议是编写自己的适配器。第一个应该只需要几个小时。另外,这样它就可以完全满足您的需求。编辑:所以回答你的问题,不,我没有找到任何最新的。
    • 这就是我的想法,我会自己写,我可能会更新它,并分享它,也许这会对其他人有所帮助^^。再次感谢!
    猜你喜欢
    • 2014-07-11
    • 1970-01-01
    • 2010-12-13
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 2014-01-01
    • 2021-03-15
    相关资源
    最近更新 更多