基于jQuery XML的模板引擎 [英] jquery xml based template engine
问题描述
从缺乏信息的角度来看,我猜想下面的问题可能像他们所说的那样少了滑雪道".
Judging from the lack of info around, I'm guessing the following question maybe a little "off piste" as they say..
我正在尝试找到基于XML的javascript(基于JQuery的首选)模板引擎.
I am trying to find an XML based javascript (pref. JQuery based) templating engine..
有点像说Ext.JS(Sencha)怎样做事或SPRY数据集.精简的东西..
A little like say how Ext.JS (Sencha) do things, or SPRY datasets. Something lite..
很明显,基于JSON的有很多,尽管我有必须使用XML的要求,但我知道有充分的理由.
Obviously there are lots of JSON based ones, and for good reason I know, although I have a requirement that has to use XML.
我一直在使用John Resig的微模板引擎处理JSON数据,真的想要基于XML的数据类似的东西吗?
I have been using John Resig's micro-templating engine for JSON data, and really want something similar for XML based data?
有什么想法吗?还是徒劳?
Any ideas? or futile?
推荐答案
好吧..当然XSL模板可能是我所忽略的显而易见的事情..只是想要像JQuery的XML操作一样直接的东西,但是应用于HTML模板.
Okay.. of course XSL templates is probably the obvious thing I was overlooking.. just wanted something as straight forward as JQuery's XML manipulation, but applied to a HTML template.
位于www.dhtmlx.com及其客户端XSLT的AJAX功能上.一切似乎都很好.以下是有兴趣的人的摘录:
Settled on www.dhtmlx.com and their AJAX function which does client side XSLT. All seems to work very nicely. A snippet is shown below for anyone who is interested:
JavaScript:
Javascript:
dhtmlxAjax.get('/PageTemplates/membernotifications_template.xsl', function (xslLoader) {
var xmlLoader = dhtmlxAjax.getSync('/ajaxget/getmembernotifications.ashx');
$('#notifications').html(xmlLoader.doXSLTransToString(xslLoader.xmlDoc.responseXML));
});
您当然需要DHX javascript库.链接在上面.
You will need the DHX javascript library of course.. the link is above.
正如您所看到的,我们引用.XSL模板,然后引用实际的数据源,在我的情况下,是从仅写出XML的.ashx页面引用的.
As you can see, we reference the .XSL template and then the actual data source, in my case from a .ashx page which just writes out the XML.
然后,我们使用JQuery(不过,您当然可以直接引用DOM项)将XSL和XML绑定到输出(对于我而言)具有ID = notifications的DIV中.
We then, using JQuery (however you could refer to a DOM item directly of course), bind the XSL and XML to output into (in my case) a DIV with ID=notifications.
这篇关于基于jQuery XML的模板引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!