问题描述
在我了解到Ember Data中的BasicAdapter已被删除之后,我决定从Ember Data切换到Ember Model,因为我使用的API并不完全是RESTful(而且我通常需要更多的灵活性)。
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).
我想知道如何使用Ember Data中的FixtureAdapter处理我的代码中的某些部分。
I'm wondering how to "translate" some parts of my code that used to work with the FixtureAdapter from Ember Data.
这里例如,我得到一个配置文件列表,但我想直接重定向到第一个。这意味着,访问 / profiles
将会将我重定向到类似 / profiles / 123
的内容。
我如何使用Ember Model做到这一点? (使用FixtureAdapter作为起点)。
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)
}
当我使用Ember Model进行此操作时,我的控制台中出现以下错误:
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'
感谢您的帮助!
推荐答案
尝试使用:
App.Profile.fetch().then(profiles)
fetch()函数将给你一个承诺,你可以在
The fetch() function will give you a promise that you can call then() on
这篇关于从Ember Data FixtureAdapter切换到Ember Model FixtureAdapter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!