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

问题描述

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

任何想法这是发生什么?一些关于我应该研究的建议?



谢谢。

解决方案

您不能将多个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 属性



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



示例@


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?

thanks.

解决方案

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

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: '/'
        })
    })
});

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

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

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

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

10-28 23:52