本文介绍了JavaScript支持哪种好的模板语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

模板在已有的编程语言中是一项相当健康的业务,但有哪些好的可以在JavaScript中处理?

Templates are a pretty healthy business in established programming languages, but are there any good ones that can be processed in JavaScript?

模板我的意思是文档接受数据对象作为输入,将数据插入某种序列化标记语言,并输出标记。众所周知的例子是,原始PHP,。

By "template" I mean a document that accepts a data object as input, inserts the data into some kind of serialized markup language, and outputs the markup. Well-known examples are JSP, the original PHP, XSLT.

好我的意思是它声明性且容易一个要编写的HTML作者,它是健壮的,并且它也支持其他语言。比我所了解的选项更好。一些不好的例子:

By "good" I mean that it's declarative and easy for an HTML author to write, that it's robust, and that it's supported in other languages too. Something better than the options I know about. Some examples of "not good":

字符串数学:

element.innerHTML = "<p>Name: " + data.name
    + "</p><p>Email: " + data.email + "</p>";

显然太笨重,HTML结构不明显。

clearly too unwieldy, HTML structure not apparent.

XSLT:

<p><xsl:text>Name: </xsl:text><xsl:value-of select="//data/name"></p>
<p><xsl:text>Email: </xsl:text><xsl:value-of select="//data/email"></p>

//结构上这很好用,但让我们面对它,XSLT会让HTML开发人员感到困惑。

// Structurally this works well, but let's face it, XSLT confuses HTML developers.

Trimpath:

<p>Name: ${data.name}</p><p>Email: ${data.email}</p>

//这很好,但处理器仅支持JavaScript,而且语言类似于原语()。

// This is nice, but the processor is only supported in JavaScript, and the language is sort of primitive (http://code.google.com/p/trimpath/wiki/JavaScriptTemplateSyntax).

我很想看到JSP或ASP或PHP的一个子集移植到浏览器,但我还没有找到。

I'd love to see a subset of JSP or ASP or PHP ported to the browser, but I haven't found that.

人们在JavaScript中使用这些天的模板是什么?

What are people using these days in JavaScript for their templating?

几个月后,这里发布了大量可行的模板语言,但大多数语言都不能用于任何其他语言。大多数这些模板都无法在JavaScript引擎之外使用。

After a few months there have been plenty of workable template languages posted here, but most of them aren't usable in any other language. Most of these templates couldn't be used outside a JavaScript engine.

例外是微软 - 您可以在浏览器或任何其他ASP中处理相同的ASP发动机。由于您已经绑定到Microsoft系统,因此它有自己的一组可移植性问题。我已经将其标记为答案,但我仍然对更便携的解决方案感兴趣。

The exception is Microsoft's -- you can process the same ASP either in the browser or in any other ASP engine. That has its own set of portability problems, since you're bound to Microsoft systems. I've marked that as the answer, but am still interested in more portable solutions.

感谢所有输入到目前为止!

Thanks for all the input so far!

推荐答案

即将推出的ASP.NET AJAX 4.0还有客户端模板功能。

There is Client-Side Template functionality coming to the coming ASP.NET AJAX 4.0.

此外,您还可以使用Microsoft AJAX Library(它本身就是ASP.NET AJAX的JavaScript部分,不使用ASP.NET。

Also, you can use the Microsoft AJAX Library (which is the JavaScript part of ASP.NET AJAX) by itself, without using ASP.NET.

这篇关于JavaScript支持哪种好的模板语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 13:32
查看更多