Dostęp do kontrolerów z innych kontrolerów
Buduję aplikację do zarządzania projektami przy użyciu wersji ember.js-pre3 ember-data 11.
Jak zainicjować kilka kontrolerów i udostępnić je globalnie. Na przykład mam kontroler currentUser i userController, do którego potrzebuję dostępu w każdym stanie. Kiedyś miałem następujący kod w funkcji Ember.ready, ale to już nie działa. Myślę, że sposób, w jaki to robiłem, był przeznaczony do debugowania.https://github.com/emberjs/ember.js/issues/1646
Stara droga:
window.Fp = Ember.Application.create
ready: () ->
# Initialize Global collections
appController = @get 'router.applicationController'
store = @get 'router.store'
# User controller sets usersController binding on applicationController
# fetches all team users from server
# json returned from server includes flag "isCurrent"
usersController = @get 'router.usersController'
usersController.set 'content', store.findAll(Fp.User)
appController.set 'usersController', usersController
# CurrentUserController
# sets currentUserController binding on applicationController
# finds currentUser from usersController
currentUserController = @get 'router.currentUserController'
currentUserController.set 'content', usersController.get('findCurrentUser')
appController.set 'currentUserController', currentUserController
@_super()
Jaki jest właściwy sposób dostępu do kontrolera currentUser we wszystkich stanach aplikacji.