数据模板的JScript和.net实现

王朝c#·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

最近玩.NET和JSCRIPT

把基于JSCRIPT 的trimpath的TEMPLATE封装到了服务端。

下列程序需要.NET环境支持。

import lint;

import System;

var data = {

products : [ { name: "mac", desc: "computer",

price: 1000, quantity: 100, alert:null },

{ name: "ipod", desc: "music player",

price: 200, quantity: 200, alert:"on sale now!" },

{ name: "cinema display", desc: "screen",

price: 800, quantity: 300, alert:"best deal!" } ],

customer : { first: "John", last: "Public", level: "gold" }

};

var cart_jst=

"Hello ${customer.first} ${customer.last}.<br/> Your shopping cart has ${products.length} item(s): <table> <tr><td>Name</td><td>Description</td> <td>Price</td><td>Quantity & Alert</td></tr> {for p in products} <tr><td>${p.name|capitalize}</td><td>${p.desc}</td> <td>$${p.price}</td><td>${p.quantity} : ${p.alert|default:\"\"|capitalize}</td> </tr> {forelse} <tr><td colspan=\"4\">No products in your cart.</tr> {/for} </table> {if customer.level == \"gold\"} We love you! Please check out our Gold Customer specials! {else} Become a Gold Customer by buying more stuff here. {/if}"

var str = lint.Tpl.parseTemplate(cart_jst).process(data);

Console.WriteLine(str);

http://info95.vicp.net/tpl.rar

解压得到tpl.dll

jsc /r:tpl.dll test.js

生成test.exe

运行test即可。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航