成功保存新的 Project 对象后,我应该如何处理转换到不同的视图?如果我的验证通过,我想提交 @transaction 并转换到 Projects 索引视图。
控制器:
DA.ProjectsController = Em.ArrayController.extend
createProject: (project) ->
@transaction = DA.store.transaction()
p = @transaction.createRecord(DA.Project, project)
validation_errors = p.validate()
if validation_errors
DA.displayError validation_errors
else
@transaction.commit()
### What should be here to transition the route/view? ###
router.transitionTo('projects') # Like this?
DA.get('router').send('projects') # This?
###################################################
路由器:
DA.Router = Em.Router.create
location: 'history'
root: Em.Route.extend
index: Em.Route.extend
route: '/'
redirectsTo: 'projects'
projects: Em.Route.extend
route: '/projects'
index: Em.Route.extend
router: '/'
connectOutlets: (router) ->
router.get('applicationController').connectOutlet('projects', DA.Project.find())
showProject: Em.Route.transitionTo('project')
project: Em.Route.extend
route: '/projects/:project_id'
connectOutlets: (router, project) ->
router.get('applicationController').connectOutlet('project', project)
newProject: Em.Route.extend
route: '/projects/new'
connectOutlets: (router) ->
router.get('applicationController').connectOutlet('projectsNew')
doProjects: (router) ->
router.transitionTo('projects')
doProjectsNew: (router) ->
router.transitionTo('newProject')