Ember:处理路径时出错。无法点击API

时间:2018-05-03 20:45:48

标签: ember.js

此代码有效(硬编码):

import Ember from 'ember';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';

export default Ember.Route.extend(AuthenticatedRouteMixin, {
    model() {
        let stars = [
            {
                key: "johnlennon",
                logoUrl: "https://www.images.com/johnl.png",
                name: "John Lennon",
                alive: false
            }
        }
    }
});

当我这样做时,它没有(来自API):

import Ember from 'ember';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
import config from '../../../../../config/environment';

export default Ember.Route.extend(AuthenticatedRouteMixin, {
    model() {
        const token = this.get('session.data.authenticated.token');
        return Ember.RSVP.hash({
            stars: Ember.$.getJSON(Ember.$.getJSON(`${config.APP.starsAPI}/api/stars?authorizationToken=${token}`))
        });
    }
});

我收到的错误:

  

jquery.js:9175 GET   http://localhost:4242/stars/948/connect/[object%20Object] 404(不是   实测值)

     

ember.debug.js:30291处理路线时出错:   stars.show.connect.stars.index

正如您可能已经猜到的那样,我需要它来使用API​​。为什么这会给我错误?

2 个答案:

答案 0 :(得分:0)

在这次改变后它起作用了:

import Ember from 'ember';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
import config from '../../../../../config/environment';

export default Ember.Route.extend(AuthenticatedRouteMixin, {
    model() {
        const token = this.get('session.data.authenticated.token');
        return Ember.$.getJSON(`${config.APP.starsApi}/api/stars?authorizationToken=${token}`).then(function(retVal){
            return retVal;
        });
    }
});

答案 1 :(得分:0)

看起来你已经链接了`Ember。$。getJSON()方法。

return Ember.$.getJSON(`${config.APP.starsApi}/api/stars?authorizationToken=${token}`).then(function(retVal){
    return retVal;
});

这应该可以正常工作