2

I am trying to show a TopController property in a TopView template. In TopView, I have sectionBinding: 'controller.section'.

From my understanding of Ember.js, in TopView, the controller property should refer to my TopController. Yet it seems to refer to ApplicationController? Read on:

In my router, I have router.set('topController.section', 'index');... But that doesn't seem to do anything in this case. Changing it to router.set('applicationController.section', 'index'); works and the {{section}} part in the TopView template changes to "index".

I have created two fiddles showing my issue. The first one doesn't work:

FAULTY -> http://jsfiddle.net/8tQ4q/4/

The second one does work:

WORKS -> http://jsfiddle.net/8tQ4q/5/

The only difference is the topController / applicationController part in router.set(). Any idea what I am doing wrong?

Kasper Tidemann
  • 488
  • 1
  • 3
  • 15

2 Answers2

3

I'm not sure why you're expecting topController to be connected to TopView. You haven't done anything to make this connection. I think you may be confused because connectOutlet('top') would create a TopView that is connected to topController. However, you aren't doing this anywhere in your app.

You also don't need the sectionBinding. If you have a controller defined on your view, it will be the default context.

Peter Wagenet
  • 4,976
  • 22
  • 26
  • 1
    +1, and I would complete by saying that the second example works simply because the topView's controller fallback to its parentView's controller, which is applicationController. – sly7_7 Aug 10 '12 at 17:48
  • Thanks for the answer, Peter. I'm sorry about the confusion. From my understanding based on what I've read so far, there should always be a connection between Controller and View (reflected in the 'controller' property per default) - which is not the case then. It's my hope to be able to aid you in writing documentation onwards, but I feel a bit lost at this point (without having read the entire source code). :( Anyway, thanks again, I'll give it another go. – Kasper Tidemann Aug 11 '12 at 02:34
  • @Peter Wagenet, I found an example by pangratz here that seems to do the same as I'm attempting, yet it works: http://stackoverflow.com/questions/11628489/emberjs-how-to-mark-active-menu-item-using-router-infrastructure - Where exactly does pangratz make the connection between the NavigationController and the NavigationView? – Kasper Tidemann Aug 11 '12 at 11:31
  • Okay, never mind. I read most of the source and I get the concepts now. I don't know where I read about the naming part, but that's clearly wrong. Thanks Peter and @sly7_7 for your input, greatly appreciated! – Kasper Tidemann Aug 12 '12 at 19:26
-1

I think what you want to do is this:

router.get('topController').set('section', 'index');
buuda
  • 1,427
  • 7
  • 8
  • I tried your suggestion in this fiddle: http://jsfiddle.net/8tQ4q/8/ - Unfortunately, it still doesn't work. I can't help but think this is a bug of some sort? – Kasper Tidemann Aug 10 '12 at 14:56
  • `set` also takes a path. So `set('topController.section', 'index')` should behave the same as `get('topController').set('section', 'index')`. – Peter Wagenet Aug 10 '12 at 16:12