【发布时间】:2014-08-14 15:27:57
【问题描述】:
我的 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}} 通过它时,我收到一条消息,告诉我它试图循环遍历上述字符串而不是数组。
任何帮助将不胜感激!
乔
【问题讨论】:
标签: javascript model-view-controller ember.js