为什么这个 Ember.js 应用程序在 Firefox 中失败? [英] Why does this Ember.js app fail in Firefox?

查看:27
本文介绍了为什么这个 Ember.js 应用程序在 Firefox 中失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的 Ember.js 应用程序,它可以在 IE 和 Chrome 中正常运行,但在 Firefox(9.0.1 和 10.0)中却失败了.有什么理由吗?代码如下:

I have a very simple Ember.js app which works correctly in IE and Chrome, but fails in Firefox (9.0.1 and 10.0). Any reason why? Here's the code:

<!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>

推荐答案

firefox的错误是

The error in firefox is

uncaught exception: Error: <Ember.View:ember143> - Unable to find template "my-template".

这似乎表明模板脚本尚未在应用执行时进行评估.解决方法是等待onload.像这样包裹你的 appendTo:

This would seem to indicate that the template script has not been evaluated at the point where the app executes. The solution is to wait for onload. Wrap your appendTo like this:

$(function() {
    App.view.appendTo('#container');
});

这篇关于为什么这个 Ember.js 应用程序在 Firefox 中失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆