使用与ASP.NET Underscore.js [英] Using Underscore.js with ASP.NET

查看:139
本文介绍了使用与ASP.NET Underscore.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在比较不同的JavaScript模板引擎,看看哪一个让我对大型数据集的最佳性能。一,我跑过是 Underscore.js 。不过,我一直无法得到任何工作的例子。我的模板是这样的:

I've been comparing different JavaScript template engines to see which one gives me the best performance for large sets of data. One that I ran across is Underscore.js. However, I haven't been able to get any of the examples working. My template looks like:

<% _.each(projects(), function(project) { %>
   <tr>
      <td><%= project.code %></td>
      <td><%= project.request %></td>
      <td><%= project.stage %></td>
      <td><%= project.type %></td>
      <td><%= project.launch %></td>
   </tr>
<% }) %>

然而,当我运行该页面我得到了一个服务器端的ASP.NET例外,因为它试图编译在&LT的文本;%...%GT; 标签:

Compiler Error Message: CS1026: ) expected
Line 826:                     <% _.each(projects(), function(project) { %>

我无法找到一种方式来逃避这些标签,也不是我能找到一种方法来配置下划线使用不同的语法。有一种解决方法,或者下划线和ASP.NET只是彼此不兼容?

I was unable to find a way to escape these tags, nor was I able to find a way to configure Underscore to use a different syntax. Is there a workaround, or are Underscore and ASP.NET simply incompatible with each other?

推荐答案

与JSP同样的问题,所以我们这样做:

Same issue with JSP, so we do this:

_.templateSettings = {interpolate : /\{\{(.+?)\}\}/g,      // print value: {{ value_name }}
                      evaluate    : /\{%([\s\S]+?)%\}/g,   // excute code: {% code_to_execute %}
                      escape      : /\{%-([\s\S]+?)%\}/g}; // excape HTML: {%- <script> %} prints &lt;script&gt;

这将允许您使用的标记输出所有的各种版本:插值,评价和逃避

This will allow you to use all the various versions of the tag outputs: interpolation, evaluation and escaping.

这篇关于使用与ASP.NET Underscore.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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