在asp.net网页表单中使用下划线模板_.template() [英] Using underscore templates _.template() in asp.net web forms

查看:106
本文介绍了在asp.net网页表单中使用下划线模板_.template()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用带有underscore.js Backbone.js的模板在一个asp.net web表单应用程序并在问题到来的模板。

I'm trying to use backbone.js with underscore.js templates in an asp.net web forms application and coming across a problem with the templates.

<script id='Template' type='text/template'>
<span class="description <%=Description%>"></span>
</script>

这个页面将不会在asp.net web表单工作,因为web表单使用相同的&LT;%和%>标记为强调模板,从而导致在运行时出现错误

This page won't work in asp.net webforms because webforms uses the same <% and %> notation as underscores templates, resulting in an error at runtime

编译器错误信息:CS0103:名称'说明'不存在
  在目前情况下

Compiler Error Message: CS0103: The name 'Description' does not exist in the current context

有没有办法让asp.net web表单这个工作,否则我将不得不使用不同的模板库?

Is there a way to get this working in asp.net web forms, or will I have to use a different templating library?

推荐答案

您可以覆盖underscore.js模板设置。看看_.templateSettings和文件(<一个href=\"http://documentcloud.github.com/underscore/#template\">http://documentcloud.github.com/underscore/#template).您可以定义自己的正则表达式的嵌套数据。

You can override underscore.js template settings. Take a look at _.templateSettings and the documentation (http://documentcloud.github.com/underscore/#template). You can define your own regex for nesting data.

例如。

_.template("hello <?= name ?>", {"name": "Mike"}, {"interpolate": /<?=([\s\S]+?)%>/g) ?>})

这篇关于在asp.net网页表单中使用下划线模板_.template()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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