admin管理员组文章数量:1296841
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 pletion)
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.
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 pletion)
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.
Share edited May 17, 2013 at 15:28 4imble asked Oct 4, 2011 at 12:05 4imble4imble 14.4k15 gold badges76 silver badges132 bronze badges4 Answers
Reset to default 9To get around this I create two html helpers for the begining of my script tag and the end of my script tag. 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. It is avaliable trough new bindings:
- if
- ifnot
- with
- foreach!
you can read more in Steve Sanderson's announce: http://blog.stevensanderson./2011/08/31/knockout-1-3-0-beta-available/ (1. Control flow bindings)
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. 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]
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:
<%= StartTemplate("WidgetTemplate")%>
...actual template HTML goes here...
<%= EndTemplate() %>
本文标签: javascriptKnockoutJs and TemplatesNo code highlightingcompletion in visual studioStack Overflow
版权声明:本文标题:javascript - KnockoutJs and Templates - No code highlightingcompletion in visual studio? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741645785a2390178.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论