Home >Web Front-end >JS Tutorial >ejs v9 javascript template system_javascript skills

ejs v9 javascript template system_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:55:131143browse

This version is to change back to the v6 form. The backend data still has @frontend for easy viewing and debugging. I also discussed this necessity with a TX front-end engineer yesterday. Obtain the variables that need to be filled in the template, and then compare them with the JSON passed from the backend to verify the data as early as possible. For this technique, you can look at PHP's variable naming, which is prefixed with $.
In previous versions, if the output statement contained a semicolon or comma, an error would be reported

Copy the code The code is as follows:



Because the internally generated string looks like this:
__views(data.tr.name;)
In order to prevent users from accidentally adding a comma or semicolon, this version automatically handles it for you.

Copy the code The code is as follows:
rlastSemi = /[,;]s*$/
// Slightly
case "="://process the variables returned by the background (output to the page);
logic = els[0].substring(1);
if(logic.indexOf("@")!==-1){
temp.push( startOfHTML, logic.replace(rAt,"$1 data.").replace(rlastSemi,''), endOfHTML );
}else{
temp.push( startOfHTML, logic.replace(rlastSemi,''), endOfHTML );
}
break;

Example
The following is a template, placed within the script tag that the browser will ignore parsing JS code. Note that trs and href are preceded by the @ identifier.

Copy code The code is as follows: