First, the grammar
Calling external functions in template code requires a helper method to register
Template.helper (name, callback)
Ii. use of "instances"
Original: http://blog.csdn.net/u011413061/article/details/50498470
Prerequisite: Replace use
HTML code:
<!--Data Container -<DivID= "Content"></Div><!--/Data Container -<ScriptID= "Test"type= "text/html"> /*to format a time object*/{{ time|DateFormat:'yyyy mm month DD Day HH:MM:SS'}}</Script>
JavaScript code
/** * Format dates, * @param date to format * @param format formatted pattern String * Supported pattern letters are: * y: Year, * M: Month of the Year (1-12), * d: Day of the Month (1-31), * H: Hours (0-23), * m: Min (0-59), * s: S (0-59), * s: msec (0-999), * Q: Quarter (1-4) * @return String * @author Yanis.wang * @see http://yaniswang.com/frontend/2013/02/16/dateformat-performance/*/Template.helper (' DateFormat ',function(date, format) {Date=NewDate (date);//new Date Object /*Date Dictionary*/ varMap = { "M": Date.getmonth () + 1,//Month"D": date.getdate (),//Day"H": date.gethours (),//hours"M": date.getminutes (),//points"S": Date.getseconds (),//seconds"Q": Math.floor ((Date.getmonth () + 3)/3),//Quarterly"S": Date.getmilliseconds ()//milliseconds }; /*Regular Replacement*/format= Format.replace (/([YMDHMSQS]) +/g,function(all, t) {varv =Map[t]; if(v!==undefined) { if(All.length > 1) {v= ' 0 ' +v; V= V.substr (v.length-2); } returnv; } Else if(t = = = ' Y '){ return(Date.getfullyear () + "). substr (4-all.length); } returnAll ; }); /*return to itself*/ returnformat;});/*Data*/vardata ={time: (NewDate). ToString (),};/*Rendering*/varhtml = template (' Test ', data);/*binding*/document.getElementById (' content '). InnerHTML = html;
Js-template-art "Four" is registered by helper method, calling external method