Ember js你好世界节目不起作用

时间:2015-02-02 06:06:36

标签: ember.js ember-data

我正在尝试用ember js创建一个hello world程序。 下面是代码

        <html>
        <head>
            <script src="libraries/jquery.js"></script>
            <script src="libraries/handlebars.js"></script>
            <script src="libraries/ember.js"></script>
        </head>
        <body>
        <script type="text/x-handlebars">
        {{#view App.UserView }}
        <b>Name:</b> {{person.name}}
        {{/view}}
        </script>
        <button onclick="btnTest_OnClick()" id="btnTest">Click me to change</button>
          <script type="text/javascript"> 
                $(document).ready(function() {
                    window.App = Ember.Application.create();
                    //create class
                    App.Person = Ember.Object.extend({
                        id: 0,
                        name: ""
                    });
                    //create instance of class
                    var person = App.Person.create();
                    person.name = "Duncan";
                    person.id = 0;
                    //create controller
                    App.userController = Ember.Object.create({
                        content: person,
                        changeModel: function () {
                            this.content.set('name', 'Joe');
                        }
                    });
                    //view
                     App.UserView = Ember.View.extend({
                        nameBinding: 'App.userController.content.name'            
                    });
               }); 
              function btnTest_OnClick() {
                    App.userController.changeModel();
                }
        </script> 
        </body>
        </html> 

它没有给出任何错误消息,但该名称未显示在浏览器上 你能帮帮我吗?

1 个答案:

答案 0 :(得分:0)

你不能像那样运行emberjs。将您的应用代码移至app.js文件并包含该文件。您不需要准备好文档。 Ember为你处理。