1

I have an ArrayController that I want to display the first item's contents when the view is first accessed, at the moment I am doing it like this:

App.SomeController = Em.ArrayController.extend
  content: Ember.A()
  active: null

  contentDidLoad: ( ->
    return unless @get('content.isLoaded') || @get('content.length') == 0 || @get('active')

    @set('active', @get('firstObject'))
    App.get('router').transitionTo('root.inbox.email', @get('active'))
  ).observes('content.isLoaded')

I don't like calling the router like this from the controller.

The way the content is usually displayed is from the click of an action helper like this:

<div {{action showEmail view.content href="true"}}>

But obviously no click will happen when the page first loads.

Is there better way?

dagda1
  • 26,856
  • 59
  • 237
  • 450
  • 1
    Can you show more code? I guess you have some kind of index route and there you should setup your controllers. Which version of ember are you using? There have been some major changes in the recent version. – mavilein Jan 03 '13 at 18:47
  • Yahuda answered my question, which seems similar: http://stackoverflow.com/questions/14305255/ember-automatically-redirect-to-firstobject/14306796#14306796 – Chris Nolet Jan 14 '13 at 07:35

0 Answers0