在我的index.html中,我有空的<body>
標記。我有一個視圖加載視圖的內容(通過icanhaz)。我想有一個全球區域(綁定到body標籤),並通過視圖在其中放置一些內容。我遇到的問題是它會將全新的身體標記放入現有的身體標記中。backbone.js/marionette.js全球地區:身體內部身體
這是應用程序:
var Application = new Marionette.Application();
Application.addRegions({
bodyRegion: new Marionette.Region({el: "body"})
});
Application.addInitializer(function(options) {
Application.bodyRegion.show(new RootView());
});
這是我rootView:
Backbone.View.extend({
tagName: 'body',
initialize: function(options) {
logger.init('root');
loader.loadTemplate(template);
this.headerView = new HeaderView();
this.usersView = new UsersView();
},
render: function() {
logger.render('root');
this.$el.html(ich.rootTemplate);
this.headerView.setElement(this.$el.find('#header')).render();
this.usersView.setElement(this.$el.find('#main')).render();
return this;
}
});
這是我root.ich:
<script id="rootTemplate" type="text/html">
<div id="header"></div>
<div class="container" id="main"></div>
</script>
我有問題是,後渲染我已經在另一個標籤裏面有一個標籤。如果我不使用木偶和使用純骨幹觀點相反,具有以下幾行:
var rootView = new RootView();
rootView.setElement('body').render();
一切工作正常。我究竟做錯了什麼?
然後我從'Application.bodyRegion.show(new RootView())'行中得到'未捕獲錯誤:HierarchyRequestError:DOM異常3';' – ducin
Dunno Marionnette,我想你的視圖元素不能是該區域的元素? – Loamhoof
沒有,似乎並不是那樣,但你肯定有一些DOM插入錯誤。 – Loamhoof