Can you place a jsRender template within a .js file? The reason is, I want to contain my entire plugin, which I want to have use a template instead of writing all the code to dynamically create the nodes, in a single javascript file. Is this possible? If so how? If not, what are my options?
相关问题
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Include empty value fields in jQuery .serialize()
- Disable Browser onUnload on certain links?
- how to get selected text from iframe with javascri
If you create a template in a script block, you can get the compiled function, convert to string, and put it into your script file:
Run the code:
var compiledFunctionString = $( "#myTemplate" ).template().toString();
Copy the string value of the resulting compiledFunctionString (which will be of the form
"function anonymous($data, $view) { ...content... }"
) and put it into your script file as:function myTemplate($data, $view) { ...content... }
.Now you can use it as in:
think about jQuery plugin: tmpl http://api.jquery.com/jquery.tmpl/