我知道 ember js 适用于单页应用程序,而且您似乎可以将 ember js 应用程序本地化到单个 dom 容器而不是整个页面,所以我想知道 ember js 是否适合高级应用程序小部件的创建,不仅仅是一个稍微花哨的下拉菜单或任何东西,而是一个更复杂的小部件,它可以处理自己的 restful 资源等。或者以这种方式使用 ember.js 是不是有点矫枉过正?
如果它适用于小部件,当 ember 应用程序来自不同的作者时,是否有可能无需重新编码小部件以在同一页面上使用多个 ember 小部件应用程序,我的意思是我可以的一个例子在同一页面上轻松拥有来自不同来源的多个 jquery 插件,而不会发生任何冲突。
最佳答案
Ember.js 对于复杂的小部件来说并不过分,而且完全可以在一个页面上使用多个 ember 小部件应用程序。但是,需要对代码进行一些修改。来自Ember.js code :
"By default, Ember.Application will begin listening for events on the document. If your application is embedded inside a page, instead of controlling the entire document, you can specify which DOM element to attach to by setting the
rootElement
property:
MyApp = Ember.Application.create({
rootElement: $('#my-app')
});
The root of an Ember.Application must not be removed during the course of the page's lifetime. If you have only a single conceptual application for the entire page, and are not embedding any third-party Ember applications in your page, use the default document root for your application.
You only need to specify the root if your page contains multiple instances of Ember.Application."
现在明显的问题是如何在加载 JavaScript 之前为每个小部件设置 rootElement。我可以想到多种方法来做到这一点,但最好的方法取决于您尝试做的任何设置。希望这能让您走上正确的道路。
关于javascript - ember.js 小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8509076/