本文介绍了使用DS.FixtureAdapter时无法查询Emberjs Model的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法查询我的模型。我不知道我在做错什么。



我的商店定义为

  App.Store = DS.Store.extend({
revision:12,
adapter:DS.FixtureAdapter
});

我的模型定义,

  var Feature = DS.Model.extend({
name:DS.attr('string'),
description:DS.attr('string'),
parent:DS.belongsTo('SimpleTestManager.Feature'),
DS.belongsTo('SimpleTestManager.Project'),
children:DS.hasMany('SimpleTestManager.Feature'),
要求:DS.attr('string')
});

App.Feature.adapter = DS.FixtureAdapter.create();

App.Feature.FIXTURES = [
{
id:1,
名称:我的第一个功能,
描述:一些描述 ,
parent:null,
project:1,
children:[2],
要求:这是我的第一个功能,它有很多要求。
},
{
id:2,
名称:一个子功能,
描述:一些子功能,
父1,
项目:1,
children:[],
要求:这是一个子功能。
}
];

当我在命令行中运行以下命令



$ {pre> >> App.Features.find({id:'1'})
错误:断言失败:未实现:您必须覆盖DS.FixtureAdapter: :queryFixtures方法支持查询灯具存储。


解决方案

感谢您的帮助,



从我可以收集的内容中,find()方法调用findQuery(),它调用FixturesAdapter中的queryFixtures()。这个未被实现的想法是开发人员将其扩展到实现自己的find(),以便存储不同的搜索结果。对于参数的基本过滤器,我能够做到这一点。

  //////存根数据存储夹具适配器/////// 
App.Store = DS.Store.extend({
revision:12,
// adapter:'DS.RESTAdapter',
adapter:DS.FixtureAdapter.extend({
queryFixtures:function {
console.log(query);
console.log(type);
返回fixtures.filter(function(item){
for(prop在查询中){
if(item [prop]!= query [prop]){
return false;
}
}
return true;
});
}
})
});


I'm unable to query my models. I don't know what I'm doing wrong.

I have my store defined as

App.Store = DS.Store.extend({
        revision: 12,
        adapter: DS.FixtureAdapter
    });

And my model defined,

var Feature = DS.Model.extend({
    name: DS.attr('string'),
    description: DS.attr('string'),
    parent: DS.belongsTo('SimpleTestManager.Feature'),
    DS.belongsTo('SimpleTestManager.Project'),
    children: DS.hasMany('SimpleTestManager.Feature'),
    requirements: DS.attr('string')
});

App.Feature.adapter = DS.FixtureAdapter.create();

App.Feature.FIXTURES = [
    {
        id: 1,
        name: "my first feature",
        description: "some description",
        parent: null,
        project: 1,
        children:[2],
        requirements: "This is my first feature.  It has many requirements."
    },
    {
        id: 2,
        name: "a sub feature",
        description: "some sub feature.",
        parent: 1,
        project: 1,
        children:[],
        requirements: "This is a sub feature."
    }
];

When I run the following in the command line

>>App.Features.find({id:'1'})
Error: assertion failed: Not implemented: You must override the DS.FixtureAdapter::queryFixtures method to support querying the fixture store.
解决方案

Thanks for your help in trying to figure this out.

From what I've been able to gather, the find() method calls findQuery(), which calls queryFixtures() in the FixturesAdapter. The idea for this not being implemented is for developers to extend this to implement their own find() for stubbing out different search results. For a basic filter on parameter, I was able to just do this.

////// Stub data store fixture adapter ///////
App.Store = DS.Store.extend({
    revision: 12,
    //adapter: 'DS.RESTAdapter',
    adapter: DS.FixtureAdapter.extend({
        queryFixtures: function(fixtures, query, type) {
            console.log(query);
            console.log(type);
            return fixtures.filter(function(item) {
                for(prop in query) {
                    if( item[prop] != query[prop]) {
                        return false;
                    }
                }
                return true;
            });
        }
    })
});

这篇关于使用DS.FixtureAdapter时无法查询Emberjs Model的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 15:29