Switch from Ember Data FixtureAdapter to Ember Mod

2019-09-05 14:02发布

问题:

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