我有一个非常简单的Ember.js应用程序,可以在IE和Chrome中正常运行,但在Firefox(9.0.1和10.0)中失败.有什么理由吗?这是代码:
<!doctype html>
<html>
<head>
<title>Template Name</title>
</head>
<body>
<script type="text/x-handlebars" data-template-name="my-template">
{{App.user.name}}
</script>
<div id="container"></div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="http://cloud.github.com/downloads/emberjs/ember.js/ember-0.9.4.js"></script>
<script type="text/javascript">
window.App = Ember.Application.create();
App.user = Ember.Object.create({
name: 'John'
});
App.view = Ember.View.create({
templateName: 'my-template'
});
App.view.appendTo('#container');
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
Mar*_*ten 13
firefox中的错误是
uncaught exception: Error: <Ember.View:ember143> - Unable to find template "my-template".
Run Code Online (Sandbox Code Playgroud)
这似乎表明模板脚本尚未在应用程序执行时进行评估.解决方案是等待onload.包裹你appendTo喜欢这个:
$(function() {
App.view.appendTo('#container');
});
Run Code Online (Sandbox Code Playgroud)