gpt4 book ai didi

ember.js - 使用 DS.FixtureAdapter 时无法查询 Emberjs 模型

转载 作者:行者123 更新时间:2023-12-03 22:48:26 25 4
gpt4 key购买 nike

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

我将我的商店定义为

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'),
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."
}
];

当我在命令行中运行以下命令时
>>App.Features.find({id:'1'})
Error: assertion failed: Not implemented: You must override the DS.FixtureAdapter::queryFixtures method to support querying the fixture store.

最佳答案

我设法通过使用 David Lai 的答案解决了上述错误,但没有从 DS.Store 扩展(Ember Data 1.0.beta.1 之后的新方法):

App.FixtureAdapter = DS.FixtureAdapter.extend({
queryFixtures: function(records, query, type) {
return records.filter(function(record) {
for(var key in query) {
if (!query.hasOwnProperty(key)) { continue; }
var value = query[key];
if (record[key] !== value) { return false; }
}
return true;
});
}
});


App.Store = DS.Store.extend({
adapter: 'Fixture'
});

关于ember.js - 使用 DS.FixtureAdapter 时无法查询 Emberjs 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16753150/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com