2012-07-20 68 views
9

我收到提示与Ember 0.9.8.1不能使用相同的根元素(体)多次在Ember.Application

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

任何知道这是怎么回事?我应该看看哪些建议?

谢谢。

+0

可以告诉你一些代码? – Rajat 2012-07-20 05:10:55

+0

看起来与http://stackoverflow.com/questions/8509076/ember-js-widgets – iX3 2012-09-27 20:18:19

+1

有关,根据这个pull请求,“这意味着你正在创建多个Ember.Applications,而不指定不同的rootElement。默认的rootElement是body。” https://github.com/emberjs/ember.js/issues/1192 – iX3 2012-09-27 20:20:38

回答

12

您不能将几个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: '/' 
     }) 
    }) 
}); 

在这里,我们明确地设置到应用程序将绑定的DOM元素,使用rootElement财产。

默认情况下,灰烬应用结合body,所以如果你有两次,他们冲突...

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

+0

这消除了警告消息,但在您的小提琴中,App2.ApplicationView实际上并未加载。 – 2012-09-20 16:24:27

+0

的确,我不再工作了。我看看那个。 Thx的信息。 – 2012-09-21 06:23:36

+0

我刚刚填补了一个问题(https://github.com/emberjs/ember.js/issues/1395),因为它看起来像一个回归。 – 2012-09-21 06:38:22

相关问题