我刚刚开始使用 Ember.js 构建一个测试应用程序。我正在尝试绑定到,ApplicationController
以便我的名字在application
模板中呈现。我无法让它工作!
我正在关注http://emberjs.com/guides/templates/handlebars-basics/中提供的信息
这是我正在使用的代码:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<link href="/Content/css/style.css" rel="stylesheet" type="text/css" />
<script src="/Scripts/lib/jquery.js" type="text/javascript"></script>
<script src="/Scripts/lib/handlebars.js" type="text/javascript"></script>
<script src="/Scripts/lib/ember.js" type="text/javascript"></script>
</head>
<body>
<script type="text/x-handlebars">
<h1>Welcome to my test application</h1>
<div>
Hello, <strong>{{firstName}} {{lastName}}</strong>!
</div>
</script>
<script type="text/javascript">
$(function () {
MyApp = Ember.Application.create();
MyApp.ApplicationController = Ember.Controller.extend({
firstName: "Jones",
lastName: "Ross"
});
});
</script>
</body>
</html>
输出是:
Welcome to my test application
Hello, !
firstName
似乎lastName
是undefined
!不会产生错误。