0
votes

I'm using the render controller extensively in my app and am having trouble understanding the logic around Controller creation.

The code in question uses this (cut-down) template (using emblem.js):

    .span4
      render "learningNeeds" # models loaded in learningNeeds controller
    .span8
      render "notices" student.room.notices # student is defined on the top-level controller
      render "observations" # models loaded in observations controller

and the setupController for the template's Route:

App.ParentRoute = Ember.Route.extend

  setupController: (controller, model) ->
    console.log "ParentRoute setupController"

    controller.set('student', model.get('students').objectAt(0))
    @set('controller.controllers.observations.showFilters', true) # this works
    @set('controller.controllers.learning_needs.showFilters', true) # this works
    @set('controller.controllers.notices.showAdd', true) # this doesn't work
    App.currentUser = model

I'm setting the content of the learning_needs and observations controllers in observers within their respective controllers, so I'm not passing in any model to the render call in the template.

With the notices controller I'm passing in the student.room.notices as the 2nd parameter to the render call.

Now the issue is that the I'm seeing different notices controllers when I render the template to that in the Parent setupController method. That is, they have different ember ids. The controller at @set('controller.controllers.notices.showAdd', true) is different to that rendered by the template.

If I remove the student.room.notices model from the template and just use `render "notices" then the same controller is used and I can set the showAdd property and have it display in the template. The problem then is it doesn't contain any models.

The relevant docs say the render view helper will Get (or generate) the singleton instance of AuthorController but this doesn't seem the case for me.

Can anyone shed any light on this behaviour?

thanks,

Martin

1
which version of ember.js are you using?intuitivepixel
Having looked at the docs again I now see this: When a model is provided it gets a unique instance of the corresponding controller. Looks like the behaviour I'm seeing is expected. Now I'd just like to figure out how to get a reference to this generated controller so I can set some attributes on it.Martin Stannard

1 Answers

0
votes

I think you should use property bindings.

In NoticesController: showAdd: Ember.computed.alias('parentController.noticesShowAdd'

In setupController: controller.set('noticesShowAdd', true)

Then you don't have to worry about figuring out how to get a reference to the notices controller.

Note, if render is called inside an each, you may need to use target instead of parentController.