2012-12-29 41 views
5

Tôi không tìm thấy bất kỳ tài liệu hay nào để bắt đầu với Ember.js. Xin hãy giúp tôi, Đây là một ví dụ đơn giản tôi đã thử từ http://emberjs.com/documentation/ Nhưng không có gì hiển thị trên màn hình.Bắt đầu với Ember.js

Error: MyApp is not defined 

Javascript: app.js

MyApp.president = Ember.Object.create({ 
    firstName: "Barack", 
    lastName: "Obama", 
    fullName: function() { 
    return this.get('firstName') + ' ' + this.get('lastName'); 
    // Tell Ember that this computed property depends on firstName 
    // and lastName 
    }.property('firstName', 'lastName') 
}); 

HTML

<p> 
<script type="text/x-handlebars"> 
    The President of the United States is {{MyApp.president.fullName}}. 
</script> 
</p> 

tôi bao gồm tất cả các file JS từ nhận Kit bắt đầu.

+0

"Tôi không tìm thấy bất kỳ tài liệu nào tốt" ??? Bạn đã xem http://emberjs.com/documentation/ chưa? –

+0

Có, Nhưng, ví dụ trong tài liệu không hoạt động. xem mã của tôi –

+0

Rất tiếc, xin lỗi. Se câu trả lời của tôi –

Trả lời

6

Bạn đã quên để xác định MyApp, trong đó có được một thể hiện của Ember.Application:

var MyApp = Ember.Application.create({}); 

Đây là một cái comp hướng dẫn nâng cấp tôi đã tìm thấy vài tuần trước, có thể nó sẽ hữu ích cho mục đích học tập của bạn: http://www.appliness.com/flame-on-a-beginners-guide-to-ember-js/

5

Bạn phải xác định MyApp

Tôi đã tạo ra một ví dụ làm việc here. Nhấp vào nút Chạy để xem kết quả.

HTML

<p> 
<script type="text/x-handlebars"> 
    The President of the United States is {{MyApp.president.fullName}}. 
</script> 
</p>​ 

window.MyApp = Ember.Application.create(); 

MyApp.president = Ember.Object.create({ 
    firstName: "Barack", 
    lastName: "Obama", 
    fullName: function() { 
    return this.get('firstName') + ' ' + this.get('lastName'); 
    }.property('firstName', 'lastName') 
}); 
​