I am using the micro template ( Micro Template ) in my project. Below is the sample
<script type="text/html" id="user_tmpl">
<% for ( var i = 0; i < users.length; i++ ) { %>
<li><a href="<%=users[i].url%>"><%=users[i].name%></a></li>
<% } %>
</script>
Is it possible to call a javascript function say a simple function like this:
function SubstringText(input,length) {
return input.substring(1, length);
}
on users[i].name property ?
You can call it directly in the script, for example:
<script type="text/html" id="user_tmpl">
<% for ( var i = 0; i < users.length; i++ ) { %>
<li><a href="<%=users[i].url%>"><%=SubstringText(users[i].name, 5)%></a></li>
<% } %>
</script>
I'm not sure what length
you want here, just replace 5
with whatever that is in the example above.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.