您不能在Ember.Application中多次使用相同的根元素(正文)

man*_*nni 10 ember.js

我在使用ember 0.9.8.1时遇到错误

You cannot use the same root element (body) multiple times in an Ember.Application 
Run Code Online (Sandbox Code Playgroud)

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

谢谢.

Mik*_*ski 13

您不能将多个Ember应用程序绑定到同一个DOM元素,因为它会与DOM维护发生冲突.

但是,您可以在同一页面中实现多个Ember应用程序.尝试类似的东西:

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: '/'
        })
    })
});
Run Code Online (Sandbox Code Playgroud)

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

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

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