在Visual Studio编辑HTML文件时,支持Javascript的模板标记 [英] Support for Javascript template markup when editing HTML files in Visual Studio

查看:305
本文介绍了在Visual Studio编辑HTML文件时,支持Javascript的模板标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由JavaScript加载和使用使用underscore.js模板来呈现内容的一些HTML文件。它们包括标记如下所示:

I have some HTML files that are loaded by Javascript and used to render content using underscore.js templates. They include markup like the following:

<div class="subitem <%= (i==0 ? "first" : "") %>" data-cid="<%=model.cid %>" >

当我在Visual Studio 2010中编辑HTML文件,它不处理得太好用的&lt;%%>和&lt;%=%>模板标签。例如,有几个squigglies在上面标记(未知CSS类我,意外的标记等)。同样的问题也适用于与由使用大括号为他们的标签等模板库,如胡子和JQuery的模板标签。

When I edit the HTML files in Visual Studio 2010, it doesn't cope too well with the <% %> and <%= %> template tags. For example, there are several squigglies in the above markup ("unknown css class i", "unexpected token" etc). The same problem applies with tags used by other template libraries, such as Mustache and JQuery Templates which use curly braces for their tags.

我想编辑忽略模板标签中的任何code。是否有解决这个问题的方式配置的Visual Studio要做到这一点,或者一个插件?

I'd like the editor to ignore any code within the template tags. Is there a way of configuring Visual Studio to do this, or a plug-in that solves the problem?

推荐答案

有关的胡子和jQuery模板,在&LT创建它们C $ C>键入属性以外的其他的JavaScript。 jQuery的模板:

For mustache and jquery template, create them in <script> tag, then set the type attribute to other than that of javascript. For jquery template:

<script id="userTemplate" type="text/x-jquery-tmpl">
    <option value="{{=UserID}}">{{=FullName}}</option>
</script>
<script id="deptTemplate" type="text/x-jquery-tmpl">
    <option value="{{=DepartmentID}}">{{=DepartmentName}}</option>
</script>

然后你可以提取这样的内容

Then you may extract the content like this

$("#userTemplate").html() // to get the content

至于&LT;%,我目前不知道如何让VS忽略它,但我对此表示怀疑。

As for <%, I currently do not know how to make VS ignore it, though I doubt it.

更新

好吧,既然你使用的是underscore.js,为什么不改变 _。templateSettings 使用其他符号

Well, since you're using underscore.js, why not change the _.templateSettings to use another symbol.

这篇关于在Visual Studio编辑HTML文件时,支持Javascript的模板标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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