我正在学习使用Ember开发Web应用程序。就像你看到的那样,我的测试代码只是在视图中显示一个文本。
当我使用ember-1.0.pre.js
时,它可以正常工作,但当我更改为ember-1.0.0-pre.2.js
时,会出现下一个错误:Uncaught Error: "<TestApp.ApplicationView:ember177> - Unable to find template "application"
。使用上一版本的ember:ember-latest.js
,没有错误,但文本没有出现。在最后两种情况下,当我检查生成的html时,我意识到手柄脚本没有被处理并保留在浏览器中的html中。
在Ember Blog中,他们列出了版本之间的变化,但显然与我的问题无关。
我应该对这个简单的代码做些什么改变?
HTML
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="http://code.jquery.com/jquery-1.7.2.js"></script>
<script src="http://cloud.github.com/downloads/wycats/handlebars.js/handlebars-1.0.rc.1.js"></script>
<script src="http://cloud.github.com/downloads/emberjs/ember.js/ember-1.0.pre.js"></script>
<!--<script src="http://cloud.github.com/downloads/emberjs/ember.js/ember-1.0.0-pre.2.js"></script>-->
<!-- <script src="http://cloud.github.com/downloads/emberjs/ember.js/ember-latest.js"></script>-->
<script src="app.js"></script>
</head>
<body>
<h1>Test Application</h1>
<script type="text/x-handlebars" data-template-name="application">
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="test">
<h3> {{view.text}}</h3>
</script>
</body>
JavaScript的:
TestApp = Ember.Application.create();
TestApp.ApplicationController = Ember.Controller.extend();
TestApp.ApplicationView = Ember.View.extend({
templateName: 'application'
});
TestApp.TestController = Ember.Controller.extend();
TestApp.TestView = Ember.View.extend({
text: 'This is a sample text',
templateName: 'test'
});
TestApp.Router = Ember.Router.extend({
root: Ember.Route.extend({
index: Ember.Route.extend({
route: '/',
connectOutlets: function(router) {
router.get('applicationController').connectOutlet('test');
}
})
})
});
TestApp.initialize();
答案 0 :(得分:0)
尝试设置路由器:
App.Router.map(function(match){
match('/').to('application',function(match){
match('/').to('test')
});
});
App.TestRoute = Ember.Route.extend({
this.render('test', {
into:'application'
});
})
看看这是否有帮助