Ember JS - 返回字符串文字的ArrayController属性

时间:2014-08-14 15:27:57

标签: javascript model-view-controller ember.js

我的EmberJS App中有以下代码

// 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}}参数时,函数本身将作为字符串文字返回

e.g。 &#34;功能....&#34;

因此,在尝试通过它{{#/ each}}时,我收到一条消息,告诉我它试图遍历上面的字符串而不是数组。

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:1)

通过查看代码应该使用&#34;内容&#34;来回答我自己的问题。作为财产而不是其他的情节。 d&#39;哦

相关问题