我有一个控制器content
绑定到一个对象,该对象从不同的源异步加载数据。我希望在加载完成时呈现数据。这很好用,但是当我想要更改数据时,#each block不会重新渲染它。
App.PopularTracks = Ember.Object.create({
tracks: [],
load: function() {
var self = this;
var tracks = [];
LFM.get("chart.getHypedTracks", {limit: 5}, function(data) {
// push each track to tracks in a loop, then
self.set("tracks", tracks);
});
// This method has also other asynchronous calls that work similar,
// but #each block doesn't rerender on `tracks` change.
}
});
App.PopularTracksController = Ember.ArrayController.extend({
contentBinding: "App.PopularTracks.tracks"
});
App.PopularTracksView = Ember.View.extend({
templateName: "popularTracks"
});
答案 0 :(得分:0)
在你的例子中,“self.set”应该是“this.set”吗?
同样使用arrayController,而不是像使用常规控制器的属性那样定位它的内容,你只需要定位内容参数:
{{#each controller}}
print this for every item in the "content" array!
{{/each}}
如果你这样做:
{{#each controller.content}}
某些属性和绑定不会正确重新呈现