2012-07-09 24 views
8

Trong hướng dẫn tôi có thể tìm thấy:Emberjs rootElement

" Nếu bạn đang nhúng một ứng dụng Ember vào một trang web hiện có, bạn có thể có nghe sự kiện thiết lập cho một yếu tố cụ thể bằng cách cung cấp một tài sản rootElement:

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

"

Vui lòng cho tôi ví dụ cách sử dụng nó một cách đúng đắn.

Trả lời

24

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(); 

Đây là JSFiddle: http://jsfiddle.net/MikeAski/xtzNB/

+6

đã câu trả lời này trả lời câu hỏi của bạn? Nếu vậy, bạn nên chấp nhận nó. –

Các vấn đề liên quan