Ember应用套件,带有余烬数据 [英] Ember App Kit with ember data

查看:83
本文介绍了Ember应用套件,带有余烬数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 ember应用程序工具包和ember启动一个新项目数据使用ES6。我设法使用以下代码在 adapter.js中创建一个商店。

I'm trying to start a new project with ember app kit and ember data using ES6. I've managed to create a store using the following code in adapter.js

var ApplicationAdapter = DS.FixtureAdapter.extend();
export default ApplicationAdapter;

但是,我没有创建模型并访问它。在 models / account.js 我有这个

However, I'm failing to create a model and access it. In models/account.js I have this

var Account = DS.Model.extend({
  name: DS.attr('string')
});

Account.FIXTURES = [
  {
    'id': 1,
    'name': 'Acc 1'
  }, {
    'id': 2,
    'name': 'Acc 2'
  }
]

export default Account;

和我的 routes / accounts.js 我有这个:

var AccountsRoute = Ember.Route.extend({
  model: function() {
    var store = this.get('store');
    return store.find('account');
  }
});
export default AccountsRoute;

在这个阶段,我只是想从屏幕上显示的灯具中获取一个帐户列表。该路由工作很好,如果我放入静态数据(如索引路由),那么一切正常。但是,使用上面的代码,我遇到麻烦

At this stage I'm simply trying to get a list of accounts from the fixtures displayed on screen. The route works nicely and if I put in static data (like the index route) then all works fine. However, with the code above, I run into trouble

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

我在哪里出错?

推荐答案

您的帐户模型正在使用 DS.RESTAdapter 而不是 DS.FixtureAdapter ,因为您正在将适配器设置为 ApplicationAdapter ,预期为 AccountAdapter 。所以你从ajax收到一个错误,可能是因为url与服务器不匹配。

Your Account model is using the DS.RESTAdapter instead of the DS.FixtureAdapter, because you are setting the adapter in ApplicationAdapter, the expected is AccountAdapter. So you receive an error from the ajax, probably because the url does not match a server.

配置 DS.FixtureAdapter 每个模型使用:

var AccountAdapter = DS.FixtureAdapter.extend();
export default AccountAdapter; 

或作为所有型号的全局适配器:

Or as global adapter for all models:

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

我希望它有助于

这篇关于Ember应用套件,带有余烬数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆