2
我想代替在#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"]
因此,如果我理解正確,你不想在你的視圖中調用'modal('show')',而是想讓Bootstrap爲你做到這一點,所以你可以呈現任何內部模式? – j03w