我想#content
先动态显示模态对话框,然后再显示模板,而不是动态渲染模板。负责自动显示包含所选模板的模式的代码应该在哪里?毕竟,取消后如何关闭和删除模态类?这是当前代码:git。我正在学习骨干,不知道正确的模式是什么。
会话路由器:
($, Backbone, App, Session, Layout, AlertQueue) ->
class App.Routers.SessionsRouter extends Backbone.Router
initialize: (options) ->
@user = options.user
@token = options.token
@session = new Session(@user)
@user.on('change', =>
@session = new Session(@user)
@token.fetch()
)
routes:
"signup": "newRegistration"
"signin": "newSession"
newRegistration: ->
View = require 'views/registrations/new_view'
Model = require 'models/registration'
@view = new View(model: new Model(), user: @user)
# Layout.setContent(@view)
# Dialog.show(@view)??
newSession: ->
View = require 'views/sessions/new_view'
@view = new View(model: @session, user: @user, token: @token)
# Layout.setContent(@view)
布局助手,现在在静态容器中显示内容:
($, Backbone, App) ->
class Layout extends Backbone.Model
setContent: (content) ->
do @currentContent.close if @currentContent?
@currentContent = content
($ '#content').html content.render().el
App.Helpers.Layout = new Layout
当前模态模板:
#dialog.modal.hide.fade
.modal-header
%a.close{href: "#"} ×
/ %h3=title
.modal-body
#dialog_content
.modal-footer
%a.btn.danger.yes Yes
%a.btn.secondary.no No
当前模式对话框视图:
($, Backbone, App) ->
class App.Views.Common.DialogView extends Backbone.View
template: JST["common/dialog"]
initialize: (options) ->
super(options)
render: ->
$(@el).html(@template())
$('.modal', @el).modal()
return @
show: ->
$('.modal', @el).modal('show')
hide: ->
$('.modal', @el).modal('hide')
当前对话框初始化程序:
($, Backbone, App, FormView, DialogModalView) ->
class App.Views.Common.DialogView extends FormView
className: -> "modal"
initialize: ->
view = new DialogModalView()
$(view.render().el).find(".modal-body").append(@template())
$(view.render().el.children).modal('show')
会话视图扩展了对话框视图:
($, Backbone, App, Session, DialogView) ->
class App.Views.Sessions.NewView extends DialogView
template: JST["sessions/new"]