简体   繁体   English

Backbone.js内联模板在Opera中不起作用

[英]Backbone.js inline templates not working in Opera

I've created a backbone.js app which uses inline templates, example of below: 我已经创建了一个使用内联模板(例如下面的示例)的steel.js应用程序:

<script type="text/html" id="header-template">
<div class='header'>
<strong><%= name %></strong>
</div>
</script>

Then in the the View: 然后在视图中:

template = _.template($("#header-template").html());

In Opera this throws an error due to $("#header-template").html() returning null. 在Opera中,由于$("#header-template").html()返回null,这将引发错误。 Does anyone know how to fix this issue? 有人知道如何解决此问题吗?

Thanks 谢谢

Update: 更新:

The error I'm getting in the console is Unhandled Error: 'App.view.header' is not a constructor . 我在控制台中遇到的错误是Unhandled Error: 'App.view.header' is not a constructor When I update underscore.js and backbone.js to the latest versions I also get this error in Chrome. 当我将underscore.js和boneline.js更新到最新版本时,我在Chrome中也收到此错误。

The header is defined like this: 标头的定义如下:

App.view.header = App.view.header || {} 

App.view.header = Backbone.View.extend({
...
});

and rendered like this in the router: 并在路由器中这样渲染:

$('header').html( new App.view.header().render().el);

Another update 另一个更新

I've created a tiny backbone.js app which has the same problem: 我创建了一个有相同问题的微小的bone.js应用程序:

http://goo.gl/KoOvq http://goo.gl/KoOvq

You could wrap the template in a function and call it only when needed. 您可以将模板包装在一个函数中,并仅在需要时调用它。

I like this way more because if you start to put your templates in another files they will be loaded only when needed, the way you are doing now they are loaded at the app start. 我更喜欢这种方式,因为如果您开始将模板放入其他文件中,则仅在需要时才加载模板,而现在的方式是在应用程序启动时加载它们。

template = function(variables){ return _.template(template, variables) } 模板=函数(变量){return _.template(模板,变量)}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM