【发布时间】:2014-06-03 06:49:19
【问题描述】:
我使用本指南为 Ember Data 创建自定义适配器:http://emberjs.com/api/data/classes/DS.Adapter.html
在我的 app.js 中,我有以下内容:
App.store = DS.Store.create({
adapter: 'MyAdapter'
});
我创建了适配器:
App.MyAdapter = DS.Adapter.extend({
createRecord: function(store, type, record) {
console.log('create');
},
deleteRecord: function(store, type, record) {
console.log('delete');
},
find: function(store, type, id) {
console.log('find');
},
findAll: function(store, type, sinceToken) {
console.log('findAll');
},
findQuery: function(store, type, query) {
console.log('findQuery');
},
updateRecord: function(store, type, record) {
console.log('updateRecord');
}
});
我创建了一个模型:
App.Post = DS.Model.extend({
title: DS.attr,
body: DS.attr,
author: DS.attr
});
然后在我的路线中:
this.store.createRecord('post', {
title: 'Rails is Omakase',
body: 'Lorem ipsum',
author: 'asd'
});
var post = this.store.find('post');
console.log(post);
很遗憾,这不起作用,因为控制台输出中有几个错误:
Assertion failed: Unable to find fixtures for model type App.PostAssertion failed: The response from a findAll must be an Array, not null-
TypeError: Cannot read property 'map' of null。
所以我的第一个猜测是,它找不到我的自定义适配器,因为如果调用该函数(console.log('find')...)也没有日志记录。文档甚至是最新的吗?字符串MyAdapter 是否正确?不应该是这样吗:
App.store = DS.Store.create({
adapter: 'App.MyAdapter'
});
没有任何作用。我做错了什么?
还有一个问题:有没有适合 web 套接字的 ember 数据适配器?
【问题讨论】:
标签: ember.js ember-data adapter