Gev*_*ous 5 ember.js ember-data ember-app-kit
我正在尝试使用ember app kit和使用ES6的ember数据开始一个新项目.我已经设法使用以下代码创建商店adapter.js
var ApplicationAdapter = DS.FixtureAdapter.extend();
export default ApplicationAdapter;
Run Code Online (Sandbox Code Playgroud)
但是,我无法创建模型并访问它.在models/account.js我有这个
var Account = DS.Model.extend({
name: DS.attr('string')
});
Account.FIXTURES = [
{
'id': 1,
'name': 'Acc 1'
}, {
'id': 2,
'name': 'Acc 2'
}
]
export default Account;
Run Code Online (Sandbox Code Playgroud)
在我的routes/accounts.js我有这个:
var AccountsRoute = Ember.Route.extend({
model: function() {
var store = this.get('store');
return store.find('account');
}
});
export default AccountsRoute;
Run Code Online (Sandbox Code Playgroud)
在这个阶段,我只是想从屏幕上显示的灯具中获取一个帐户列表.路由很好,如果我输入静态数据(如索引路由),那么一切正常.但是,使用上面的代码,我遇到了麻烦
DEPRECATION: Action handlers contained in an `events` object are deprecated in favor of putting them in an `actions` object (error on <Ember.Route:ember352>)
at Object.triggerEvent (http://localhost:8000/vendor/ember/index.js:30519:13)
at trigger (http://localhost:8000/vendor/ember/index.js:29641:16)
at handleError (http://localhost:8000/vendor/ember/index.js:29903:9)
at invokeCallback (http://localhost:8000/vendor/ember/index.js:8055:19)
at null.<anonymous> (http://localhost:8000/vendor/ember/index.js:8109:11)
at EventTarget.trigger (http://localhost:8000/vendor/ember/index.js:7878:22)
at http://localhost:8000/vendor/ember/index.js:8180:17
at Object.DeferredActionQueues.flush (http://localhost:8000/vendor/ember/index.js:5459:24)
at Object.Backburner.end (http://localhost:8000/vendor/ember/index.js:5545:27) index.js:394
Error while loading route:
Object {readyState: 4, getResponseHeader: function, getAllResponseHeaders: function, setRequestHeader: function, overrideMimeType: function…}
index.js:394
Uncaught #<Object> index.js:30566
Run Code Online (Sandbox Code Playgroud)
我哪里错了?
您的Account模型使用DS.RESTAdapter而不是DS.FixtureAdapter,因为您正在设置适配器ApplicationAdapter,预期的是AccountAdapter.所以你从ajax收到错误,可能是因为url与服务器不匹配.
要配置DS.FixtureAdapter每个模型使用:
var AccountAdapter = DS.FixtureAdapter.extend();
export default AccountAdapter;
Run Code Online (Sandbox Code Playgroud)
或者作为所有模型的全局适配器:
App.Store = DS.Store.extend({
adapter: DS.FixtureAdapter
});
Run Code Online (Sandbox Code Playgroud)
我希望它有所帮助
| 归档时间: |
|
| 查看次数: |
2568 次 |
| 最近记录: |