[英]KnockoutJs and Templates - No code highlighting / completion in visual studio?
I have been playing with the tutorials on the knockout site and have enjoyed working with it. 我一直在玩淘汰网站上的教程,并喜欢使用它。
So i decided to make a simple site with it. 所以我决定用它制作一个简单的网站。 I was saddened to notice that i lose a lot of the support from the IDE when working with the javascript templates (highlighting, code completion) 我很遗憾地注意到在使用javascript模板时我失去了IDE的大量支持(突出显示,代码完成)
Example template: 示例模板:
<script type="text/html" id="taskTemplate">
<li>
<input type="checkbox" data-bind="checked: isDone" />
<input data-bind="value: title, enable: !isDone()" />
<a href="#" data-bind="click: remove">Delete</a>
</li>
</script>
Is this something you have to just swallow or is it avoidable / fixable? 这是你必须吞下的东西还是可以避免/可以修复的东西? Templates seem to be one of the most used ways of building up the page and so i would prefer to have the support from the IDE. 模板似乎是构建页面最常用的方法之一,所以我更希望得到IDE的支持。
To get around this I create two html helpers for the begining of my script tag and the end of my script tag. 为了解决这个问题,我创建了两个html助手,用于开始我的脚本标记和脚本标记的结尾。 Something like: 就像是:
<% Html.BeginTemplate(new { id = "features-template" }); %>
<li>
<input type="checkbox" data-bind="checked: isDone" />
<input data-bind="value: title, enable: !isDone()" />
<a href="#" data-bind="click: remove">Delete</a>
</li>
<% Html.EndTemplate(); %>
Keith proposed very good and intelligent solution. 基思提出了非常好的智能解决方案。 However I would like to let you know KO 1.3 has native templating engine. 不过我想让你知道KO 1.3有本机模板引擎。 It is avaliable trough new bindings: 通过新绑定可以实现:
you can read more in Steve Sanderson's announce: http://blog.stevensanderson.com/2011/08/31/knockout-1-3-0-beta-available/ (1. Control flow bindings) 您可以在Steve Sanderson的宣布中阅读更多内容: http : //blog.stevensanderson.com/2011/08/31/knockout-1-3-0-beta-available/ (1。控制流绑定)
So your example will have this look: 所以你的例子会看起来像这样:
<ul data-bind="foreach: tasks">
<li>
<input type="checkbox" data-bind="checked: isDone" />
<input data-bind="value: title, enable: !isDone()" />
<a href="#" data-bind="click: remove">Delete</a>
</li>
</ul>
It is the <script type="text/html"...>
tag that is stopping Visual Studio highlight this section of your markup as html. 正是停止Visual Studio的<script type="text/html"...>
标记突出显示标记的这一部分为html。 Therefore, this question/answer seems to be the closest you are going to get to an answer. 因此,这个问题/答案似乎是你最接近答案的答案。
Visual Studio - Markup syntax highlighting inside script[type:txt/html] Visual Studio - 在脚本内部突出显示标记语法[type:txt / html]
I used the accepted answer here, and since it helped me, if anyone wants actual code, here you go: 我在这里使用了接受的答案,因为它帮助了我,如果有人想要实际的代码,你可以去:
public string StartTemplate(string id)
{
return ("<script type=\"text/html\" id=\"" + id + "\">\r\n");
}
public string EndTemplate()
{
return ("</script>\r\n");
}
HTML: HTML:
<%= StartTemplate("WidgetTemplate")%>
...actual template HTML goes here...
<%= EndTemplate() %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.