Best JavaScript code snippet using wpt
template_condition.js
Source:template_condition.js
1PT.namespace('CrmCondition');2PT.CrmCondition = function () {3 var cond_type_list=['account', 'campaign', 'adgroup', 'keyword'],4 current_type=parseInt($('input[name="source_type"]').val()); //å½å页é¢çç´¢å¼5 6 var get_dangerous_info = function(){7 PT.sendDajax({'function':"crm_get_dangerous_info"});8 };9 var rjjh_remind_show_func = function(){10 var flag_obj = $("#rjjh_remind_flag");11 var flag = flag_obj.val();12 var speed = 5000;13 var obj = $("#rjjh_remind_show");14 if(flag == 0 || flag == '0'){15 obj.css({'color':'white','font-weight':300});16 } else if (flag == 1|| flag == '1'){17 obj.css({'color':'red','font-weight':600});18 speed = 400;19 flag_obj.val(2);20 } else if (flag == 2 || flag == '2'){21 obj.css({'color':'black','font-weight':300});22 speed = 400;23 flag_obj.val(1);24 }25 setTimeout(function(){rjjh_remind_show_func();},speed);26 };27 28 var init_dom=function(){29 30 var rjjh_dev = $("#rjjh_remind_dev");31 if(rjjh_dev.length > 0){32 $("#pull_but").click();33 get_dangerous_info();34 setInterval(get_dangerous_info,1000*60*5);35 rjjh_remind_show_func();36 }37 $("#base_consult_group_id").change(function(){38 PT.sendDajax({'function':"crm_get_base_user_info",'department':$(this).val(),'name_space':"CrmCondition"});39 });40 $('#campaign_mnt_type').change(function(){41 var type = $('#campaign_mnt_type').val();42 if(type=='2'){43 $("#campaign_stat_type").removeAttr('disabled');44 }else{45 $("#campaign_stat_type").attr({'disabled':'disabled'});46 }47 });48 $('#base_is_rpt').change( function(){49 var is_rpt=$(this).val();50 if (is_rpt==1) {51 $('#base_rpt_day').parent().show();52 $('.c_content .rpt ').slideDown('fast');53 $('.is_on_rpt').fadeIn('fast');54 } else {55 $('#base_rpt_day').parent().hide();56 $('.c_content .rpt ').slideUp('fast');57 $('.is_on_rpt').fadeOut('fast');58 }59 });60 $('#button_search').live('click',function(){61 //åå§åå页å¨62 $('#dynamic_pager').html('');63 $('#dynamic_pager').off('page');64 PT.CrmCondition.get_filter_result(1);65 var show_btn=$('#show_summary_rpt');66 if($('#base_is_rpt').val()==1){67 show_btn.fadeIn();68 }else{69 show_btn.fadeOut();70 }71 $('#summary_rpt_table').hide();72 });73 $('#show_summary_rpt').live('click',function(){74 var obj = $('#summary_info_tip');75 if(obj.css('display') == 'none'){76 var is_jumped=parseInt($('#base_is_jumped').val());77 PT.sendDajax({'function':'crm_statistical_summary','filter_type_index':current_type,'is_jumped':is_jumped});78 }79 obj.slideDown('fast');80 $('#summary_rpt_table').slideUp('fast');81 });82 $(".submit_msg").live('click',function(){83 var content=$('#msg_content').val();84 if (content) {85 var obj_list=get_objs_list(current_type), title=$('#msg_title').val();86 if (obj_list.length) {87 PT.show_loading('æ£å¨æ交æ¶æ¯');88 PT.sendDajax({'function':'crm_submit_msg','msg_type':$(this).attr('msg_type'),'title':title,'content':content,'obj_type':current_type,'obj_list':$.toJSON(obj_list)});89 }else{90 PT.alert('请è³å°éæ©ä¸æ¡è®°å½');91 }92 }93 });94 $('.open_msg').live('click',function(){95 var now_tr = $(this).parents('tr')[0],96 table_list=['account_table','camp_table','adg_table'],97 data_table=$('#'+table_list[current_type]).dataTable();98 if (data_table.fnIsOpen(now_tr) ){99 data_table.fnClose(now_tr);100 $(this).text('å±å¼');101 } else {102 $(this).text('æ¶ç¼©');103 var detail_str=$(now_tr).data('detail_str');104 if (detail_str && $(now_tr).attr('is_refresh')==0 ) {105 data_table.fnOpen( now_tr, $(detail_str) , 'info_row' );106 } else {107 data_table.fnOpen( now_tr, "<span class='tac'><img src='/site_media/jl/img/forecast_orde_ajax.gif'>æ£å¨å è½½ä¸ããã</span>", 'info_row tac' );108 var jq_check_box=$(now_tr).find('.kid_box');109 PT.sendDajax({'function':'crm_get_msg','obj_type':current_type,'obj_id':jq_check_box.val(),'shop_id':jq_check_box.attr('shop_id')});110 }111 }112 });113 }114 var init_common_dom=function(){115 // åå§åå
¨éæé®116 var all_select_html = "<a href='javascript:;' class='use_cache single ' ><i class='icon-lightbulb' style='color:red;font-size:20px;' ></i></a> å¤é¡µå
¨é(<span id='selected_status' style='color:gray'>å·²å
³é</span>)";117 var obj = $('#all_selected');118 obj.html(all_select_html);119 PT.CrmCondition.init_all_selected_envent();120 }121 var get_objs_list=function(obj_type){122 var objs=$('table tbody input:checked'), obj_list=[];123 objs.each(function(){124 obj_list.push({'shop_id':parseInt($(this).attr('shop_id')),'obj_id':parseInt($(this).val())});125 });126 return obj_list;127 }128 var init_data=function(type_id,data){129 var format_dict={'pay':[100,1,2],'cost':[100,1,2],'cpc':[100,1,2],'ctr':[1,100,2],'conv':[1,100,2],'budget':[100,1,2],'max_price':[100,1,2],'limit_price':[100,1,2],'cons_ratio':[1,100,0]};130 var format_id_list=[],str_list=['nick','contain','cat_id'];131 for (var k in format_dict) {132 format_id_list.push(k);133 }134 //å¦æéè¦è¿åå符串135 if(data==-1){136 return '';137 }138 if(format_dict.hasOwnProperty(type_id)) {139 var denominator=format_dict[type_id][0], multiple=format_dict[type_id][1], point=format_dict[type_id][2];140 return parseFloat((data * multiple / denominator).toFixed(point));141 } else {142 return data;143 }144 }145 var format_data=function(type_id,data){146 //æ ¼å¼åæ°æ® {key:[ multiple, denominator, point]}147 var format_dict={'pay':[100,1,2],'cost':[100,1,2],'cpc':[100,1,2],'ctr':[1,100,4],'conv':[1,100,4],'budget':[100,1,2],'max_price':[100,1,2],'limit_price':[100,1,2],'cons_ratio':[1,100,2]};148 var format_id_list=[],str_list=['nick','contain','cat_id'];149 for (var k in format_dict) {150 format_id_list.push(k);151 }152 //å¦æéè¦è¿åå符串153 if(str_list.indexOf(type_id)!=-1) {154 data=data.replace(/^\s+|\s+$/g,'');155 return (data?data:-1)156 }157 data=parseFloat(data);158 if(isNaN(data)){159 return -1;160 }161 if(format_dict.hasOwnProperty(type_id)) {162 var multiple=format_dict[type_id][0], denominator=format_dict[type_id][1], point=format_dict[type_id][2];163 return parseFloat((data * multiple / denominator).toFixed(point));164 } else {165 return data;166 }167 }168 //è·åææè¿æ»¤æ¡ä»¶169 var get_conditions=function(){170 var account_rpt_dict={}, campaign_rpt_dict={}, adgroup_rpt_dict={}, keyword_rpt_dict={},cond_dict={},171 base_special_dict={},account_special_dict={}, campaign_special_dict={}, adgroup_special_dict={}, keyword_special_dict={};172 var rpt_inputs=$('.condtion_select .rpt>span'),173 special_single_inputs=$('.condtion_select .special .single'),174 special_double_inputs=$('.condtion_select .special .double');175 //è·åæ¥è¡¨è¿æ»¤æ¡ä»¶176 rpt_inputs.each(function() {177 var cond_type=$(this).attr('id').replace('_','0').split('0'),178 min_data=$(this).find('.min').val(), max_data=$(this).find('.max').val();179 eval(cond_type[0]+'_rpt_dict')[cond_type[1]]=[format_data(cond_type[1],min_data),format_data(cond_type[1],max_data)];180 });181 //è·åå个è¾å
¥æ¡åä¸æå表çå¼182 special_single_inputs.each(function() {183 var cond_type=$(this).attr('id').replace('_','0').split('0'), cond_data=$(this).val();184 eval(cond_type[0]+'_special_dict')[cond_type[1]]=(format_data(cond_type[1],cond_data));185 });186 //è·åæ¥è¡¨ä»¥å¤çä¸å¯¹è¾å
¥æ¡çå¼187 special_double_inputs.each(function() {188 var cond_type=$(this).attr('id').replace('_','0').split('0'),189 min_data=$(this).find('.min').val(), max_data=$(this).find('.max').val();190 eval(cond_type[0]+'_special_dict')[cond_type[1]]=[format_data(cond_type[1],min_data),format_data(cond_type[1],max_data)];191 });192 for (var i in cond_type_list) {193 var cond_type=cond_type_list[i];194 cond_dict[cond_type]={'special':eval(cond_type+'_special_dict'),'rpt':eval(cond_type+'_rpt_dict')};195 }196 return [base_special_dict,cond_dict];197 }198 return {199 init:function(){200 init_dom();201 init_common_dom();202 },203 //åå§åè¿æ»¤æ¡ä»¶204 init_condition:function(base_dict,cond_dict){205 PT.show_loading('æ£å¨åå§åè¿æ»¤æ¡ä»¶');206 for (var k in base_dict) {207 $('#base_'+k).val(base_dict[k]==-1?'':base_dict[k]);208 }209 if ( $('#base_is_jumped').val()==1) {210 var source_type=parseInt($('#source_type').val()),211 jq_conditions=$('#condition_div .condtion_select'),base_div=jq_conditions.eq(0);212 for(var i=0; i<=source_type; i++){213 jq_conditions.eq(i+1).hide();214 }215 base_div.find('#base_is_jumped').parent().show();216 base_div.find('select').slice(0,3).attr('disabled','disabled');217 }218 for (var key in cond_dict) {219 var key_array = key.replace(/\s/g,'').split('_');220 if(key_array.length > 2){221 var temp_dict = cond_dict[key];222 cond_type = key_array[1];223 if (temp_dict == null){224 continue225 }226 var key_list = new Array();227 if (temp_dict.hasOwnProperty('rpt')){228 key_list.push('rpt');229 }230 if (temp_dict.hasOwnProperty('special')){231 key_list.push('special');232 }233 for(sub_key in key_list){234 render_dict = temp_dict[ key_list[sub_key] ];235 for (cond_id in render_dict){236 var data = render_dict[cond_id];237 if (data instanceof Array) {238 var min=init_data(cond_id,data[0]),max=init_data(cond_id,data[1]);239 $('#'+cond_type+'_'+cond_id).find('.min').val(min);240 $('#'+cond_type+'_'+cond_id).find('.max').val(max);241 } else {242 data=init_data(cond_id,data);243 $('#'+cond_type+'_'+cond_id).val(data);244 }245 }246 }247 }248 }249 $('#base_is_rpt').change();250 $("#base_consult_group_id").change();251 PT.hide_loading();252 if (['1131', '1159', '1223'].indexOf($('#consult_id').val()) >= 0) {253 $('.is_usable').attr('disabled', false);254 }255 },256 get_filter_result:function (page_no){257 var cond_arr=get_conditions();258 var tree_path = $("#tree_path").val();259 if (!cond_arr) {260 return false;261 }262 PT.show_loading('æ£å¨æ¥è¯¢æ°æ®');263 PT.sendDajax({'function':'crm_get_filter_result','filter_type_index':current_type,'tree_path':tree_path,'base_dict':$.toJSON(cond_arr[0]),'cond_dict':$.toJSON(cond_arr[1]),'page_no':page_no,'is_manual':true});264 },265 statistics_summary_back:function(data,error_msg){266 $('#summary_info_tip').slideUp('fast');267 var result_dict=eval(data),td_str=template.render('summary_rpt_table_td', result_dict),sum_table=$('#summary_rpt_table');268 sum_table.find('tbody tr').html(td_str);269 sum_table.slideDown('fast');270 if(error_msg != ''){271 PT.alert(error_msg);272 }273 },274 get_group_back:function (psuser_id, psuser_type,group_list, user_list) {275 var obj = $('#base_consult_group_id');276 var obj_sub = $("#base_consult_id");277 if(group_list.length > 0){278 var option_str="";279 for(var i=0;i<group_list.length;i++) {280 option_str += "<option value='"+group_list[i][0]+"'>"+group_list[i][1]+"</option>";281 }282 obj.html(option_str);283 }284 option_str="<option value='-1'>---------</option>";285 for(var i=0;i<user_list.length;i++) {286 option_str += "<option value='"+user_list[i][0]+"'>"+user_list[i][1]+"</option>";287 }288 obj_sub.html(option_str);289 if($("#base_consult_id option[value="+psuser_id+"]").length > 0){290 obj.val(psuser_type);291 obj_sub.val(psuser_id);292 }293 var is_jumped=parseInt($('#base_is_jumped').val());294 if(is_jumped==1){295 $('#button_search').click();296 } else if ($('#request_condition input').length>0) {297 // ä»ncrmè¿æ¥æ¶èªå¨æ索账æ·298 $('#condition_div input, #condition_div select:not(#base_consult_group_id, #base_rpt_day)').val(null);299 if (!$('#base_rpt_day').val()) {$('#base_rpt_day').val('7')};300 $('#request_condition input').each(function () {301 $('#'+$(this).attr('name')).val(this.value);302 });303 $('#request_condition').empty();304 $('#button_search').click();305 }306 },307 submit_msg_back:function(error_flag,obj_id_list){308 if(error_flag){309 PT.alert("æ交æ¶æ¯å¤±è´¥ï¼è¯·å·æ°é¡µé¢åéè¯");310 }else{311 PT.light_msg("","æ交æ¶æ¯æå");312 $("#modal_msg").modal('hide');313 for(var i=0;i<obj_id_list.length;i++) {314 var jq_tr=$(".kid_box[value='"+obj_id_list[i]+"']").parents('tr'),315 jq_msg_td=jq_tr.find('.msg_td');316 if (jq_msg_td.find('.open_msg').length){317 jq_tr.attr('is_refresh',1);318 }else{319 jq_msg_td.html('<a herf="javascript:;" class="open_msg cur">å±å¼</a>');320 }321 }322 }323 },324 get_msg_back:function(error_flag, obj_id, msg_list){325 var jq_tr=$(".kid_box[value='"+obj_id+"']").parents('tr'),326 table_list=['account_table','camp_table','adg_table'],327 data_table=$('#'+table_list[current_type]).dataTable();328 if(error_flag){329 var detail_str = "<span class='tac'>è·åæ¶æ¯å¤±è´¥</span>";330 }else if (msg_list){331 template.isEscape=false;332 var detail_str = template.render("msg_template", {'msg_list':msg_list});333 jq_tr.data('detail_str',detail_str);334 jq_tr.attr('is_refresh',0);335 template.isEscape=true;336 }else{337 var detail_str ="<span class='tac'>没ææ¶æ¯</span>";338 }339 jq_tr.next().find('.info_row').html(detail_str);340 },341 init_all_selected_envent:function(){342 var color_red = 'rgb(245, 46, 19)';343 var init_obj = $('#all_selected a.use_cache');344 init_obj.find('i').css('color',color_red);345 init_obj.unbind('click');346 init_obj.click(function(){347 PT.alert("å¾æ±æï¼æ¨è¿æªæç´¢åºä»»ä½ç»æï¼è¯¥æä½æ æï¼");348 });349 },350 351 get_dangerous_info_back:function(result){352 var data = eval(result);353 if(data.length > 0){354 var content = '';355 for(var i=0; i < data.length ; i ++){356 var temp = data[i];357 temp['num'] = i+1;358 temp['title'] = temp['title'] ; 359 temp['shop_ids'] = eval(temp['val']) ; 360 content += template.render('rjjh_remind_tr',temp);361 }362 363 $("#rjjh_remind_table tbody").html(content);364 $("#rjjh_remind_table").removeClass('hide');365 $("#rjjh_noremide_div").addClass('hide');366 $("#rjjh_remind_flag").val(1);367 368 } else {369 $("#rjjh_remind_table").addClass('hide');370 $("#rjjh_noremide_div").removeClass('hide');371 $("#rjjh_remind_flag").val(0);372 }373 374 },375 376 add_all_selected_envent:function(){377 var parent_obj = $("#all_selected");378 var obj_table = parent_obj.attr('table');379 var color_green = 'rgb(33, 243, 5)';380 var color_red = 'rgb(245, 46, 19)';381 var add_obj = $('#all_selected a.use_cache');382 add_obj.find('i').css('color',color_red);383 var opar_objs = $('#'+obj_table+' input[type=checkbox]');384 opar_objs.attr({'checked':false});385 opar_objs.removeAttr('disabled');386 var select_status = $('#selected_status');387 select_status.text("å·²å
³é");388 add_obj.unbind("click");389 add_obj.click(function(){390 var obj = $(this).find('.icon-lightbulb');391 if ( obj.css('color') == color_red) {392 obj.css('color',color_green);393 opar_objs.attr({'checked':true,'disabled':'disabled'});394 parent_obj.attr('is_all',1);395 select_status.css('color','red');396 select_status.text("å·²å¼å¯");397 } else {398 obj.css('color',color_red);399 opar_objs.attr({'checked':false});400 opar_objs.removeAttr('disabled');401 parent_obj.attr('is_all',0);402 select_status.css('color','gray');403 select_status.text("å·²å
³é");404 }405 });406 }407 }...
analyze.js
Source:analyze.js
1/**2 * Created by aibuz on 2017/10/11.3 */4//æ¤æ件æ¯æè·¯å±ç¤º5//å®ä¹ååï¼ä»¤ææçString对象é½æformatæ¹æ³6String.prototype.format = function (args) {7 return this.replace(/\{(\w+)\}/g, function (s, i) {8 return args[i];9 });10};11$(function() {12 init();13});14function init() {15 $.ajax({16 url: '/server_json.html',17 type: 'GET',18 data: {},19 dataType: 'JSON',20 success: function (response) {21 initTableThead(response.table_config);22 //initTableBodyOld(response.table_config, response.data_list);23 initTableBodyNew(response.table_config, response.data_list);24 }25 })26}27function initTableThead(table_config) {28 /* table_config: 循ç¯table_configæ¿å°titleï¼å¡«å
å°é¡µé¢çtable表头ä¸29 [30 {31 'q': "hostname",32 'title': '主æºå',33 },34 ]35 */36 //æ¸
空表头ï¼ä»¥å
éå¤æ·»å 37 $.each(table_config, function(index, dict) {38 //å建表头å段ï¼å¹¶æ·»å å°<thead><tr>ä¸39 var th = document.createElement('th');40 th.innerHTML = (dict['title']);41 $('#tableThead').children('tr').append(th);42 })43}44function initTableBodyOld(table_config, data_list) {45 //æè·¯åæç¨ï¼æ£å¼çç¨initTableBodyNew46 /* data_list:47 [48 {'hostname': xxx, 'sn': xxx, 'os": xxx} --> row_dict49 ]50 */51 $.each(data_list, function(index, row_dict) {52 //æ¯ä¸ªrow_dictç¸å½äºtbodyä¸çä¸è¡å
容trï¼å¾ªç¯row_dictåå
¸ï¼æ¿å°å
¶ä¸å段对åºçå¼53 var tr = document.createElement('tr');54 /*55 $.each(row_dict, function (field, value) {56 //æ¯ä¸ªvalueç¸å½äºträ¸çä¸ä¸ªtd57 var td = document.createElement('td');58 td.innerHTML = value;59 tr.append(td);60 // é®é¢ï¼row_dictæ¯åå
¸ï¼å¯¹å®ç循ç¯æ¯æ åºçï¼è¿å¯è½å¯¼è´tbodyå段å¼åthead表头对ä¸ä¸61 })62 */63 //为äºè§£å³åå
¸å¾ªç¯æ åºçé®é¢ï¼è¿éæ¹ä¸ºå¾ªç¯table_configå表ï¼å
¶ä¸åå°çå段æ¯æåºç64 $.each(table_config, function(index, dict) {65 var td = document.createElement('td');66 td.innerHTML = row_dict[dict['q']];67 tr.append(td);68 });69 $('#tableBody').append(tr);70 //åå¦åªæ¯æ°æ®åºå段å±ç¤ºï¼é£ä¹ä»¥ä¸è¿ç§å°±å¯ä»¥äºã71 });72 /* ä½æ¯ï¼é¡µé¢ä¸å±ç¤ºçæ°æ®ä¸æ¢æ¯æ°æ®åºä¸çå段ï¼è¿æéæ©æ¡ï¼ç¼è¾çé项ï¼å æ¤å端å®å¶table_config为以ä¸å½¢å¼ï¼73 [74 {75 'q': "hostname",76 'title': '主æºå',77 'text': {'tpl': '{a1}', 'kwargs': {'a1': '@hostname'}}, --> å¢å text, 以å
¼å®¹å¤çæ°æ®åºå段åå端å±ç¤ºé项78 },79 ]80 tpl å符串模æ¿ï¼ kwargsç¨äºæ¿æ¢çå
容81 æä»¬æ ¹æ®è¿ç§æ°æ®ç»æï¼å¨ä¸é¢éåinitTableBodyNewæ¥å®ç°å¡«å
表å
容82 */83}84function initTableBodyNew(table_config, data_list) {85 /* table_config = [86 {87 'q': None,88 'title': 'éæ©',89 'text': {'tpl': '<input type="checkbox" value={id}>', 'kwargs': {'id': '@id'}},90 },91 {92 'q': 'id',93 'title': 'ID',94 'text': {'tpl': '{a1}', 'kwargs': {'a1': '@id'}},95 },96 ]97 data_list = [98 {'hostname': xxx, 'sn': xxx, 'os": xxx} --> row_dict99 ]100 */101 $.each(data_list, function (index, row_dict) {102 var tr = document.createElement('tr');103 $.each(table_config, function (index, dict) {104 var td = document.createElement('td');105 var format_dict = {};106 $.each(dict.text.kwargs, function (k, v) {107 //å®ä¹ï¼å¦ææ¯ä»¥@å¼å¤´ï¼é£ä¹å°±è¡¨ç¤ºæ ¼å¼åtplæ¶ï¼ç¨@å离çå段åæ°æ®åºæ¥è¯¢ç»æï¼å¦åï¼ç´æ¥ç¨åç¬¦ä¸²æ ¼å¼å108 if (v[0] === '@') {109 var field = v.substring(1);110 format_dict[k] = row_dict[field] //以å段çæ°æ®åºæ¥è¯¢ç»æä½ä¸ºkç¨åçæ ¼å¼åå
容111 } else {112 format_dict[k] = v;113 }114 });115 td.innerHTML = dict.text.tpl.format(format_dict); //æ ¼å¼åtplå¼116 $(tr).append(td); // jQueryç´æ¥å
dom对象117 });118 $('#tableBody').append(tr);119 })120}121/*122以ä¸å°±åºæ¬åå®äºï¼åªéè¦å¨é¡µé¢ä¸å¼å
¥å³å¯ï¼123<script src="{% static 'js/analyze.js' %}"></script>124ä½æ¯å¯è½æé®é¢ï¼é£å°±æ¯è¿éå®ä¹çå½æ°å页é¢ä¸è¦ç¨å°çå
¶å®å½æ°å¯è½éåï¼ä¸ºäºé¿å
è¿ç§æ
åµï¼éè¦å©ç¨å½æ°çä½ç¨åé离125å æ¤ï¼å°å¯ä»¥å°ä»¥ä¸ä»£ç ç¨å¦ä¸ä¸ªå½æ°å
èµ·æ¥ï¼ç»æå°±æ¯åç®å½ä¸çPapa_func.jsï¼å¹¶ä¸å¢å äºæ§å¶å è½½æ¡å¨ç»ææç代ç ã...
Papa_func.js
Source:Papa_func.js
1/**2 * Created by aibuz on 2017/10/11.3 */4function f1() {5 //å®ä¹ååï¼ä»¤ææçString对象é½æformatæ¹æ³6 String.prototype.format = function (args) {7 return this.replace(/\{(\w+)\}/g, function (s, i) {8 return args[i];9 });10 };11 //页é¢å è½½ä¹åAJAXä»/server/server_json/请æ±æ°æ®ï¼æ¸²æ页é¢12 function init() {13 $('#loading').removeClass('hide'); //å»é¤loading模ææ¡éè14 $.ajax({15 url: '/server_json.html',16 type: 'GET',17 data: {},18 dataType: 'JSON',19 success: function (response) {20 console.log(response.table_config);21 console.log(response.data_list);22 initTableHead(response.table_config);23 initTableBody(response.table_config, response.data_list);24 // å»é¤loadingææ25 $('#loading').addClass('hide');26 },27 error: function () {28 // å»é¤loadingææ29 $('#loading').addClass('hide');30 }31 })32 }33 // å¡«å
表头34 function initTableHead(table_config) {35 $('#tableThead').children("tr").empty(); //å 为å¦æå次è°ç¨init()é£ä¹ä¼å¯¼è´è¡¨å¤´éå¤æ·»å ï¼å æ¤ï¼æ¯æ¬¡é½æ§è¡æ¸
空表头36 $.each(table_config, function (index, conf) {37 var th = document.createElement('th');38 th.innerHTML = conf.title;39 console.log(conf.title);40 console.log(th);41 $('#tableThead').children('tr').append(th);42 })43 }44 //å¡«å
表æ°æ®45 function initTableBody(table_config, data_list) {46 /*47 data_list = [48 {'hostname': xxx, 'sn': xxx, 'os": xxx} --> row_dict49 ]50 */51 $.each(data_list, function (index, row_dict) {52 var tr = document.createElement('tr');53 $.each(table_config, function (index, dict) {54 var td = document.createElement('td');55 /* dict:56 {57 'q': None,58 'title': 'éæ©',59 'text': {'tpl': '<input type="checkbox" value={id}>', 'kwargs': {'id': '@id'}},60 },61 {62 'q': 'id',63 'title': 'ID',64 'text': {'tpl': '{a1}', 'kwargs': {'a1': '@id'}},65 },66 */67 //td.innerHTML = row_dict[dict.q]; // è®°å½ï¼None, id, hostname, sn, os_platform...68 //undefined 2 c1.com Parallels-1A 1B CB 3B 64 66 4B 13 86 B0 86 FF 7E 2B 20 30 linux CentOS release 6.6 (Final) Kernel on an \m è¿ç»´ undefined69 var format_dict = {};70 $.each(dict.text.kwargs, function (k, v) {71 if (v[0] == '@') { //å®ä¹ï¼å¦ææ¯ä»¥@å¼å¤´ï¼é£ä¹å°±è¡¨ç¤ºæ ¼å¼åtplæ¶ï¼ç¨@åé¢çå段æ¥è¯¢æ°æ®åºçç»æï¼å¦åï¼ç´æ¥ç¨åç¬¦ä¸²æ ¼å¼å72 var name = v.substring(1);73 console.log('name is ' + name);74 format_dict[k] = row_dict[name]75 } else {76 format_dict[k] = v;77 }78 });79 td.innerHTML = dict.text.tpl.format(format_dict);80 $(tr).append(td); // jQueryç´æ¥å
dom对象81 });82 $('#tableBody').append(tr);83 })84 }85 init();86}87/*88ç¨å½æ°f1å°å
¶å®å½æ°å
èµ·æ¥ï¼åæ¥å®æäºå°è£
åä½ç¨åé离89ç¶åå¨server.htmlä¸å¼å
¥Papa_func, æ§è¡f1()å³å¯;90ä½æ¯f1è¿ä¸ªå½æ°å¨è°ç¨æ¶å¯è½åå
¶å®å½æ°å²çªï¼å æ¤ï¼å¨ä¸ä¸ä¸ªçæ¬ä¸éè¿JSçèªæ§è¡å½æ°æ¥ä»£æ¿f1()è¿ç§æåå½æ°çå°è£
91æç»çæ¬ï¼åç®å½ä¸çKing_func.js92*/93/* 使ç¨ï¼94<script src="{% static 'js/Papa_func.js' %}"></script>95<script>96 f1();97</script>...
Using AI Code Generation
1var wptools = require('wptools')2var page = wptools.page('Albert Einstein')3page.get(function(err, info) {4 if (err) {5 console.log(err)6 } else {7 console.log(info.format_dict())8 }9})10{11 "extract": "Albert Einstein (/ˈaɪnstaɪn/; German: [ˈalbɛɐ̯t ˈʔaɪnʃtaɪn] (About this soundlisten); 14 March 1879 – 18 April 1955) was a German-born theoretical physicist. He developed the theory of relativity, one of the two pillars of modern physics (alongside quantum mechanics). Einstein's work is also known for its influence on the philosophy of science. Einstein is best known in popular culture for his mass–energy equivalence formula E = mc2 (which has been dubbed \"the world's most famous equation\"). He received the 1921 Nobel Prize in Physics \"for his services to theoretical physics, and especially for his discovery of the law of the photoelectric effect\", a pivotal step in the evolution of quantum theory. Near the beginning of his career, Einstein thought that Newtonian mechanics was no longer enough to reconcile the laws of classical mechanics with the laws of the electromagnetic field. This led to the development of his special theory of relativity. He realized, however, that the principle of relativity could also be extended to gravitational fields, and with his subsequent theory of gravitation in 1916, he published a paper on the general theory of relativity. He continued to deal with problems of statistical mechanics and quantum theory, which led to his explanations of particle theory and the motion of molecules. He also investigated the thermal properties of light which laid the foundation of the photon theory of light. In 1917, Einstein applied the general theory of relativity to model the structure of the universe.",12 "image_info": {
Using AI Code Generation
1var wptools = require('wptools');2wptools.page('Albert Einstein').get(function(err, resp) {3 console.log(resp.format_dict());4});5var wptools = require('wptools');6wptools.page('Albert Einstein').get(function(err, resp) {7 console.log(resp.format_dict());8});9var wptools = require('wptools');10wptools.page('Albert Einstein').get(function(err, resp) {11 console.log(resp.format_dict());12});13var wptools = require('wptools');14wptools.page('Albert Einstein').get(function(err, resp) {15 console.log(resp.format_dict());16});17var wptools = require('wptools');18wptools.page('Albert Einstein').get(function(err, resp) {19 console.log(resp.format_dict());20});21var wptools = require('wptools');22wptools.page('Albert Einstein').get(function(err, resp) {23 console.log(resp.format_dict());24});25var wptools = require('wptools');26wptools.page('Albert Einstein').get(function(err, resp) {27 console.log(resp.format_dict());28});29var wptools = require('wptools');30wptools.page('Albert Einstein').get(function(err, resp) {31 console.log(resp.format_dict());32});33var wptools = require('wptools');34wptools.page('Albert Einstein').get(function(err, resp) {35 console.log(resp.format_dict());36});37var wptools = require('wptools');38wptools.page('Albert Einstein').get(function(err, resp) {
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Barack Obama');3page.get(function(err, resp) {4 console.log(resp);5});6{ pageid: 534366,7 'Barack Hussein Obama II (/ˈbærək huːˈseɪn oʊˈbɑːmə/ ( listen); born August 4, 1961) is an American politician and attorney who served as the 44th President of the United States from 2009 to 2017. A member of the Democratic Party, he was the first African American to be elected to the presidency. He previously served as a U.S. Senator from Illinois from 2005 to 2008 and an Illinois state senator from 1997 to 2004. Obama was born in Honolulu, Hawaii. After graduating from Columbia University in 1983, he worked as a community organizer in Chicago. In 1988, he enrolled in Harvard Law School, where he was the first black president of the Harvard Law Review. After graduating, he became a civil rights attorney and professor, and taught constitutional law at the University of Chicago Law School from 1992 to 2004. He represented the 13th District for three terms in the Illinois Senate from 1997 to 2004, running unsuccessfully in the Democratic primary for the U.S. House of Representatives in 2000. He ran in the 2004 Democratic primary for the U.S. Senate seat being vacated by Republican Peter Fitzgerald, but lost to primary winner Alan Keyes. Following his election to the U.S. Senate in 2004, he was re-elected in 2006 with 70% of the vote. In 2008, Obama was nominated for president a year after his campaign began and after a close primary campaign against Hillary Clinton. He was elected over Republican John McCain and was inaugurated as president on January 20, 2009. Nine months later, he was named the 2009 Nobel Peace Prize laureate. Obama was re-elected president in November 2012, defeating Republican nominee Mitt Romney, and was sworn in for a second term on January 20, 2013. His mother, Ann Dunham, born in Wichita, Kansas, was of mostly English
Using AI Code Generation
1var wptools = require('wptools');2wptools.page('Barack Obama').get(function(err, response) {3 console.log(response.format_dict('en'));4});5{6 "dependencies": {7 }8}9{10 "dependencies": {11 },12 "scripts": {13 }14}15var wptools = require('wptools');16wptools.page('Barack Obama').get(function(err, response) {17 console.log(response.format_dict('en', 'infobox'));18});19{20 "dependencies": {21 },22 "scripts": {23 }24}25var wptools = require('wptools');26wptools.page('Barack Obama').get(function(err, response) {27 console.log(response.format_dict('en', 'infobox', 'simple'));28});29{30 "dependencies": {31 },
Using AI Code Generation
1var wptools = require('wptools');2var wpt = wptools.page('Albert Einstein');3wpt.get(function(err, response) {4 console.log(response.format_dict());5});6var wptools = require('wptools');7var wpt = wptools.page('Albert Einstein');8wpt.get(function(err, response) {9 console.log(response.format_dict());10});11var wptools = require('wptools');12var wpt = wptools.page('Albert Einstein');13wpt.get(function(err, response) {14 console.log(response.format_dict());15});16var wptools = require('wptools');17var wpt = wptools.page('Albert Einstein');18wpt.get(function(err, response) {19 console.log(response.format_dict());20});21var wptools = require('wptools');22var wpt = wptools.page('Albert Einstein');23wpt.get(function(err, response) {24 console.log(response.format_dict());25});26var wptools = require('wptools');27var wpt = wptools.page('Albert Einstein');28wpt.get(function(err, response) {29 console.log(response.format_dict());30});31var wptools = require('wptools');32var wpt = wptools.page('Albert Einstein');33wpt.get(function(err, response) {34 console.log(response.format_dict());35});36var wptools = require('wptools');37var wpt = wptools.page('Albert Einstein');38wpt.get(function(err
Using AI Code Generation
1const wptools = require('wptools')2const fs = require('fs')3const util = require('util')4const readFile = util.promisify(fs.readFile)5async function test() {6 const data = await readFile('test.txt', 'utf8')7 const result = wptools.format_dict(data)8 console.log(result)9}10test()11import wptools12page = wptools.page('Barack_Obama').get_parse()13print(page.data)14{15 "infobox": {16 "birth_date": "August 4, 1961 (age 58)",17 "spouse": "Michelle Obama (m. 1992)",
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!