Project code excerpt, dot usage of 1

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.