1

我有一个content绑定到对象的控制器,该对象从不同来源异步加载数据。我希望在加载完成后呈现数据。这工作得很好,但是当我想更改数据时,#each 块不会重新呈现它。

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"
});
4

1 回答 1

0

在您的示例中,“self.set”应该是“this.set”吗?

同样使用 arrayController,而不是像使用常规控制器的属性那样定位它的内容,您只需定位 content 参数:

{{#each controller}}
    print this for every item in the "content" array!
{{/each}}

如果你这样做:

{{#each controller.content}}

某些属性和绑定不会正确重新呈现

于 2013-05-08T22:04:34.777 回答