Emberjs - Can a local storage adapter and a data storage adapter be used simultaneously?

断了今生、忘了曾经 提交于 2019-12-25 02:33:27

问题


Can a local storage adapter and a data storage adapter be used simultaneously? Here's some example code.

VpcYeoman.ApplicationAdapter = DS.LSAdapter.extend({
      namespace: 'viewpoint-emberjs'
    });

vs.

VpcYeoman.Store = DS.Store.extend({
    revision: 12,
    adapter: DS.FixtureAdapter.extend({
        queryFixtures: function(fixtures, query, type) {            
            return fixtures.filter(function(item) {
                for(prop in query) {
                    if( item[prop] != query[prop]) {
                        return false;
                    }
                }
                return true;
            });
        }
    })

});

Fight! Or coexist??


回答1:


Yes, absolutely. You can create per-type adapters, so you can have:

App.PostAdapter = DS.FixtureAdapter.extend({
    queryFixtures: function(fixtures, query, type) {            
        return fixtures.filter(function(item) {
            for(prop in query) {
                if( item[prop] != query[prop]) {
                    return false;
                }
            }
            return true;
        });
    }
});
App.Post.FIXTURES = [];

Your other non-fixture types can omit an Adapter and instead use the ApplicationAdapter, which could be an instance of DS.RESTAdapter or LocalStorageAdapter. Optionally, you could define that adapter on the DS.Store instance.



来源:https://stackoverflow.com/questions/22510544/emberjs-can-a-local-storage-adapter-and-a-data-storage-adapter-be-used-simulta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!