有没有办法从控制器访问其他控制器的action
方法?
我已经尝试过@get('controllers.user').stopEditing()
类似下面的方法,但它似乎不起作用:
user_edit_controller.js.coffee
App.UserEditController = Ember.ObjectController.extend
needs: ['user']
title_options: ["Mr", "Mrs", "Dr", "Miss", "Ms"]
startEditing: ->
user = @get 'model'
transaction = user.get('store').transaction()
transaction.add user
@transaction = transaction
stopEditing: ->
transaction = @transaction
if(@transaction)
@transaction.rollback()
@transaction = undefined
actions:
save: ->
@transaction.commit()
@transaction = undefined
@get('controllers.user').stopEditing()
cancel: ->
@get('controllers.user').stopEditing()
user_controller.js.coffee
App.UserController = Ember.ObjectController.extend
isEditing: false
needs: ['userEdit']
actions:
startEditing: ->
userEditController = @get 'controllers.userEdit'
userEditController.set 'model', @get 'model'
userEditController.startEditing()
@set 'isEditing', true
stopEditing: ->
userEditController = @get 'controllers.userEdit'
userEditController.stopEditing()
@set 'isEditing', false
destroyRecord: ->
if window.confirm "Are you sure you want to delete this contact?"
@get('model').deleteRecord()
@get('store').commit()
# return to the main contacts listing page
@get('target.router').transitionTo 'users.index'