Emberjs rootElement [英] Emberjs rootElement

查看:90
本文介绍了Emberjs rootElement的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在指南中,我可以找到:

In guide I can find:


如果您将Ember应用程序嵌入现有站点,则可以设置事件侦听器通过提供一个rootElement属性来指定特定元素:

" If you are embedding an Ember application into an existing site, you can have event listeners set up for a specific element by providing a rootElement property:

window.App = Ember.Application.create({
  rootElement: '#sidebar'
});

请给我例子如何正确使用。

Please give me example how to use it corretly.

推荐答案

HTML p>

HTML

<script type="text/x-handlebars" data-template-name="app-view">
    My ember app view
</script>

This is a static content

<div id="app-container"></div>

This is a static content

JS

App = Ember.Application.create({
  rootElement: '#app-container'
});

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

App.Router = Ember.Router.extend({
    root: Ember.Route.extend({
        index: Ember.Route.extend({
            route: '/',

            connectOutlets: function (router) {
                // do some stuff here...
            }
        })
    })
});

App.initialize();

这是JSFiddle: http://jsfiddle.net/MikeAski/xtzNB/

Here is the JSFiddle: http://jsfiddle.net/MikeAski/xtzNB/

这篇关于Emberjs rootElement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆