完全に機能するレイアウトビューがあります。4 つの子ビューの 1 つに、「イベント」を作成するためのボタンがあります。クリックすると、子ビューを別の追加イベント ビューに置き換えたいと思います。
追加イベント ビューがメイン レイアウト ロジックで起動されるのか、子ビュー内で起動されるのかわかりません。
index.js (レイアウトの親ビュー)
define([
"marionette",
'app/views/images/collection',
'app/views/topPosts/collection',
'app/views/clients/collection',
'app/views/events/collection',
"tpl!app/templates/index.html"
],
function(Marionette, ImagesView, TopPostsView, ClientsView, EventsView, template) {
"use strict";
var AppLayout, layout;
AppLayout = Backbone.Marionette.Layout.extend({
template: template(),
regions: {
collection1: '#images',
collection2: '#topPosts',
collection3: '#clients',
collection4: '#events'
},
onRender: function() {
this.collection1.show(new ImagesView())
this.collection2.show(new TopPostsView())
this.collection3.show(new ClientsView())
this.collection4.show(new EventsView())
}
})
return new AppLayout()
})
event/collection.js (これにより、置換ビュー自体が起動されると思われます)
define(["marionette", "text!app/templates/events/collection.html", "app/collections/events", "app/views/events/item", 'app/views/events/create'], function (Marionette, Template, Collection, Row, CreateEventView) {
"use strict"
return Backbone.Marionette.CompositeView.extend({
template: Template,
itemView: Row,
itemViewContainer: "ul",
events: {
'click #createEvent': 'onClickCreateEvent'
},
onClickCreateEvent: function () {
//render create form over the events collection
},
initialize: function () {
this.collection = new Collection()
return this.collection.fetch()
}
})
})
event/item.js (上記のコレクションのモデル ビュー)
define(["marionette", "text!app/templates/events/item.html"], function(Marionette, Template) {
"use strict";
return Backbone.Marionette.ItemView.extend({
template: Template,
tagName: "li"
})
})
これをevent/collection.jsの中に入れてみましたが、アイテムビューが一掃されました
onClickCreateEvent: function () {
this.$el = new CreateEventView().$el
this.$el.render(); return this;
},