我的EmberJS应用程序中有以下代码

// Instantiate the Ember app
var App = Ember.Application.create();

App.Store = DS.Store.extend({
  adapter: DS.RESTAdapter
});
// Mappings for routing
App.Router.map(function () {
    this.route("index", { path : "/"});
    this.route("episode", {path : "/episode"});
});
// Home Page route
App.IndexRoute = Ember.Route.extend({
    model : function () {
        return $.getJSON('http://route-to-json/').then(function (data){
            return data;
        });
    }
});

App.EpisodeRoute = Ember.Route.extend({
    model : function () {
        return $.getJSON('http://route-to-json/episode/').then(function (data) {
            return data;
        });
    },
    setupController: function (controller, model) {
        controller.set('model', model);
    }
});

App.EpisodeController = Ember.ArrayController.extend({
    firstEpisode : function () {
        var self = this;
        this.modelFor('episode').then(function (list) {
            return list.get('firstObject');
        });
    },
    otherEpisodes : function () {
        var self = this;
        this.modelFor('episode').then(function (list) {
            return list.get('content');
        });
    }
});


在情节控制器中,第一种方法可以完全工作并呈现

<h1> {{ firstObject.programmeName }} </h1>
<time>{{ firstObject.scheduleDate }}</time>
<p>{{ firstObject.summary }}</p>


但是,当尝试使用{{otherEpisodes}}参数时,函数本身将作为字符串文字返回

例如“功能....”

因此,当尝试通过{{#/ each}}时,我收到一条消息,告诉我它试图循环上述字符串而不是Array。

任何帮助,将不胜感激!

最佳答案

通过查看代码回答了我自己的问题,应该使用“ content”作为属性,而不是otherEpisodes。天啊

09-25 19:03
查看更多