本文介绍了您不能在 Ember.Application 中多次使用相同的根元素(主体)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 ember 0.9.8.1 时遇到错误

i'm getting error with ember 0.9.8.1

You cannot use the same root element (body) multiple times in an Ember.Application 

知道这是怎么回事吗?关于我应该在哪里查看的一些建议?

any idea what this is happening? some suggestions on where i should look into?

谢谢.

推荐答案

不能将多个 Ember 应用程序绑定到同一个 DOM 元素,因为这会导致 DOM 维护冲突.

You cannot bind several Ember application to the same DOM element, as it will conflict for DOM maintenance.

您仍然可以在同一页面中实例化多个 Ember 应用程序.尝试这样的事情:

You nevertheless can instanciate several Ember applications in the same page. Try something like that:

App1 = Ember.Application.create({
    rootElement: '#app1'
});

App1.ApplicationController = Ember.Controller.extend();
App1.ApplicationView = Ember.View.extend({
    templateName: 'app1-view'
})

App1.Router = Ember.Router.extend({
    root: Ember.Route.extend({
        index: Ember.Route.extend({
            path: '/'
        })
    })
});


App2 = Ember.Application.create({
    rootElement: '#app2'
});

App2.ApplicationController = Ember.Controller.extend();
App2.ApplicationView = Ember.View.extend({
    templateName: 'app2-view'
})

App2.Router = Ember.Router.extend({
    root: Ember.Route.extend({
        index: Ember.Route.extend({
            path: '/'
        })
    })
});

在这里,我们使用 rootElement 属性显式设置应用程序将绑定到的 DOM 元素.

Here, we explicitly set the DOM element to which the app will bind, using rootElement property.

默认情况下,Ember 应用程序绑定到 body,所以如果你有两次,它们会发生冲突......

By default, an Ember app binds to body, so if you have twice, they conflict...

示例@http://jsfiddle.net/MikeAski/FMV8u/13/

这篇关于您不能在 Ember.Application 中多次使用相同的根元素(主体)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 23:52