1 functionsearchtags () {2 varList = $ (' #tags-list-select option:selected '). Val ();3 4 Console.log (list);5 6 varKeyword = $ ("#tag-search-input"). Val ();7 if($.trim (keyword). length < 1)return false;8 9 varTPL = Dot.template ($ ("#tags-tpl"). text ());Ten One varAPI = "/api/tags/search/" + list + "/" + keyword + "/0"; A$.get (API,function(data) { - varHTML =TPL (data); -$ ("#tag-result-list"). Find ("UL")). append (HTML); the }); -}
This search method has done the following several things;
1, obtain the query condition two keywords;
2, using the obtained keyword splicing URL string;
3, the initial dot template is divided into two steps:
A, get the text content of script, jquery with text (); JS with innerHTML;
B, with dot.template () processing, the content obtained in the previous step;
4, through the Ajax Get () method and the second step stitching the URL, get the data, in the callback function, the data is populated to the template, and then populate the template in the HTML specified location;
JavaScript templates in HTML
1 <!--add Label display template--2 <script id= "Tags-tpl" type= "Text/x-dot-template" >3 [ [~ It.items:item:index]] 4 [[? Item]] 5 <li><input type= ' checkbox ' name= ' tags ' value= ' [[= Item.id]] ' title= ' [[= item.t]] '/> [[[= Item.label]]] [[= ITEM.T]]6 </li>[[?] 7 [[~]] 8 </script>
Because of the swig template and dot template, the dot {{}} is changed to [[]] because it is all in {{}}.
It is actually equivalent to parameters, go out of the dot template data;
Project code excerpt, dot usage of 1