How to observes a change in the ember data store?


Here are two models from my application:

var Page = DS.Model.extend({
    PageNumber: attr('number'),
    Content: attr('string'),

var Comment = DS.Model.extend({
    Page: DS.belongsTo('page'),
   Comment: attr('string'),

The comments are retrieved when the user select the page that he wants to see with the as follows:

retrieveComments: function(selectedPageNumber) {'comment', { page: selectedPageNumber}).then(function(comments){
        console.log('comments were retrieved');

I have a controller and template that need to render the comments for the current page. This controller has a property comments that returns all comments from store for the selected page.

My problem is that this property need to automatically update when the page is changed and another comments are retrieved from the server. Please advice!


How about just defining an observer on the controller to trigger some action when the page changes?

pageNumber: 1,

pageNumberChanged: function() {
    // deal with the change