Switch from Ember Data FixtureAdapter to Ember Model FixtureAdapter

你。 提交于 2019-12-25 10:51:05

问题


After I learned that the BasicAdapter in Ember Data has been removed, I decided to switch from Ember Data to Ember Model because the API I work with is not totally RESTful (and I need more flexibility in general).

I'm wondering how to "translate" some parts of my code that used to work with the FixtureAdapter from Ember Data.

Here for example, I get a list of profiles but I want to directly redirect to the first one. That means, accessing /profiles will redirect me to something like /profiles/123. How can I do that with Ember Model? (using the FixtureAdapter, as a starting point).

App.ProfilesIndexRoute = Ember.Route.extend {

  redirect: ->
    App.Profile.find().then (profiles) =>
      @transitionTo 'profile', profiles.objectAt(0)

}

When I do that with Ember Model, I have the following error showing up in my console:

Uncaught TypeError: Object [object Object] has no method 'then' 

Thanks for your help!


回答1:


Try using:

App.Profile.fetch().then(profiles)

The fetch() function will give you a promise that you can call then() on



来源:https://stackoverflow.com/questions/18348945/switch-from-ember-data-fixtureadapter-to-ember-model-fixtureadapter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!