Summary: Because the previous project was angular development (like Vue and react), it was convenient to use two-way data bindings, and then thought about how to use the jquery framework for list generation
Knowledge Point: Regular with its inverse reference, str.replace
HTML section
<!--list li templates -<Scripttype= "text/html"ID= "Row"> <Li> <h6 class="Qa_title"><a href="Qa_article.shtml?qid={{qid}}">{{title}}</a></h6> <Div class="Qa_info C"> <span><I class="icon Icon_visit"></i> Browse:{{view_num}}</span> <span><I class="icon ICON_COMMT"></i> Answer:{{comoment_num}}</span> <span class="FR"><I class="icon Icon_date"></i> Question Time:{{add_time}}</span> </div> </li></Script>
JS section, using "\{\{(. +?)" \}\} "," IgM ", is finding the fields contained in {{}} below $ (' #row '),
Templi.replace (Reg, function (node, key) { return data.info[i][key]; });
To replace a field with content
1Gethostlist:function(){2 varrequest={}3Request.page_type= ' Get_hot_question_list ';4request.page_num= ' 0 ';5 $.ajax ({6url:fields.url+ ' Question ',7 Data:request,8DataType: "JSON",9Type: ' Post ',TenAsyncfalse, OneSuccessfunction(Result) {//Callback after success A if(result.ret==0){ - varData=Result.info; - //List Data the varReg =NewRegExp ("\{\{(. +?) \}\} "," IgM ");//matches the contents of {{}} - varTempli = $ ("#row"). html (); - varHtml= "; - for(vari=0;i<data.all_num-1;i++) { + if(!data.info[i]) Break; -html+= Templi.replace (Reg,function(node, key) { + returnData.info[i][key]; A }); at } -$ ("#qa_hot_list"). HTML (HTML); -}Else{ -Func.popshow (' #pop '); -$ (' #pop. Jx_inf '). Text (Result.info) - } in }, -Errorfunction(e) {//Callback after failure to + } -})
Effect:
Analog Template Replacement function--js