Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ember.js 将findQuery与FixtureAdapter一起使用_Ember.js_Ember Data - Fatal编程技术网

Ember.js 将findQuery与FixtureAdapter一起使用

Ember.js 将findQuery与FixtureAdapter一起使用,ember.js,ember-data,Ember.js,Ember Data,在开发应用程序时,我使用FixtureAdapter在本地加载数据 这是我的页面模型,包含夹具数据: App.Page = DS.Model.extend({ name : DS.attr('string'), parent : DS.belongsTo('App.Page'), subpages : DS.hasMany('App.Page') }); App.Page.FIXTURES = [{ id: 1, name: 'Home', su

在开发应用程序时,我使用FixtureAdapter在本地加载数据

这是我的页面模型,包含夹具数据:

App.Page = DS.Model.extend({
    name : DS.attr('string'),
    parent : DS.belongsTo('App.Page'),
    subpages : DS.hasMany('App.Page')
});

App.Page.FIXTURES = [{
    id: 1,
    name: 'Home',
    subpages: [ 2, 3, 4 ]
},{
    id: 2,
    name: 'About',
    parent: 1
},{
    id: 3,
    name: 'Contact',
    parent: 1
},{
    id: 4,
    name: 'Search',
    parent: 1
},{
    id: 5,
    name: 'Blog',
    parent: 2
}];
这是返回Fixture中所有页面对象的代码

App.PagesRoute = Ember.Route.extend({
    model: function() {
        return App.Page.find();
    }
});
这是我的应用商店:

App.store = DS.Store.create({
    revision : 11,
    adapter: DS.FixtureAdapter
});
这很好,但是如何返回根页面呢

当我在
App.Page.findQuery(App.Page,{id:1})中更改
return App.Page.find()
未捕获的适配器为null或未实现“findQuery”方法

--更新--

当我在
App.Page.find({name:'Home})中更改
return App.Page.find()
时,我得到以下错误:
未捕获类型错误:无法调用未定义的方法“\u create”


我想那是因为我的数据当时没有加载。但我认为余烬会帮我解决这个问题。

这是定义商店的正确方法:

App.Store = DS.Store.extend({
    revision : 11,
    adapter: DS.FixtureAdapter
});
注意存储中的扩展而不是创建和大写字母S
有关更多信息,请参阅。

这适用于余烬数据0.13:

App.fixtureStore = DS.Store.create({
  adapter: DS.FixtureAdapter.extend({
    queryFixtures: function(fixtures, query, type) {
      return fixtures;
    }
  })
});
进行测试时,请务必执行以下操作:

App.store = App.fixtureStore;
DS.set('defaultStore', App.fixtureStore);

调用,其注释为“实现此方法以查询设备数据”。因此,在debug中,在
商店#findQuery
上设置一个断点,并检查您从中得到了什么,您如何定义应用程序
商店