0

I have two separate views:

  1. List of posts
  2. List of comments connected with particular post

When I click on particular post in #1 view I'm displaying #2 view using simple transitionTo('comments', post). What I want to do is to mark all comments connected with the post as read when they are displayed. Let's say I want to run method: markAllAsRead(comment). Where I should put this business logic?

The ideal would be to add some hook to controller on loading. Can't find anything like this, init method is called only on first load of #2 view.

I can also run this in router in setupController

App.IndexRoute = Ember.Route.extend({ 
  setupControler: function(controller, model){
    this._super(controller, model);
    markAllAsRead(model);
  }
});

But it router doesn't seems to be designed to keep such logic.

4

2 に答える 2

1

たとえば、独自の初期化関数をコントローラーにいつでも追加できます。controller.initializeComments(model)たとえば、ルートの setupController 関数で、ルートが読み込まれるたびにコントローラーから必要なセットアップを実行できます。

于 2014-02-19T16:01:09.800 に答える