Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Templates backbone.js/marionette.js全局区域:身体内部身体_Templates_Backbone.js_Marionette - Fatal编程技术网

Templates backbone.js/marionette.js全局区域:身体内部身体

Templates backbone.js/marionette.js全局区域:身体内部身体,templates,backbone.js,marionette,Templates,Backbone.js,Marionette,在我的index.html中,我有一个空的标记。我有一个视图(通过icanhaz)为该视图加载内容。我希望有一个全局区域(绑定到body标签),并通过视图将一些内容放入其中。我的问题是,它将整个新的body标记放入现有的body标记中 这是一个应用程序: var Application = new Marionette.Application(); Application.addRegions({ bodyRegion: new Marionette.Region({el: "body"}

在我的index.html中,我有一个空的
标记。我有一个视图(通过icanhaz)为该视图加载内容。我希望有一个全局区域(绑定到body标签),并通过视图将一些内容放入其中。我的问题是,它将整个新的body标记放入现有的body标记中

这是一个应用程序:

var Application = new Marionette.Application();

Application.addRegions({
  bodyRegion: new Marionette.Region({el: "body"})
});

Application.addInitializer(function(options) {
    Application.bodyRegion.show(new 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;
    }
});
这是我的根

<script id="rootTemplate" type="text/html">
    <div id="header"></div>
    <div class="container" id="main"></div>
</script>

一切正常。我做错了什么?

标记名:“body”,创建一个新的
body
元素(您的第二个元素)。使用
el:'body'
如果您的元素必须是主体,则使用
标记名
为没有主体的视图创建一个新元素。

只需删除标记名声明,就可以了。 视图根视图将其左视图插入主体(区域el)中,为其自身创建一个div,该div将作为其在el上的部分

如果div是不可接受的,并且您需要区域el作为主体,那么 更改您的区域声明

Application.addRegions({
    bodyRegion:"body" // this will create your new region just fine with body as its el
});
你的观点应该是这样的

Backbone.View.extend({
el: 'body',  // with this line your view will be atached to an existing element in this case the 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;
}

}))

然后我从
Application.bodyRegion.show(new RootView())行中获取
Uncaught Error:HierarchyRequestError:DOM异常3
Dunno Marionnette,我想你的视图的元素不能是区域的元素?不,看起来不是,但你肯定有一些DOM插入错误。
Backbone.View.extend({
el: 'body',  // with this line your view will be atached to an existing element in this case the 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;
}