JavaScript-implemented query JSON instance code:
Below is a snippet of code strength for a better JavaScript query JSON on a network, hopefully helping you with your needs.
The code example is as follows:
/** Define template functions*/ varTemplate =function(Queryarr) {varCount = 0; for(vari = 0; i < queryarr.length; i++) { varE =Queryarr[i]; if($express) {count++; } } returncount; } /** Template creation function*/ varCreateintance =function(exp) {varFun = Template.tostring (). Replace ("$express", exp). toString (); returnEval ("0," +Fun ); } varTesttodo =function () { varTestarr =[{name:"Zhang San", age:20}, {name:"John Doe", age:25}, {name:"The King two Leper", age:28}, {name:"Xiao Zhang", age:30 } ]; varFunc = createintance ("e.age>=25"); Alert (func (Testarr)); } /****************** JS Implementation JSON query **********************/</P>//define commonly used functions varLen =function(s) {returns.length;} varleft =function(s, N) {returnS.SUBSTR (0, N); } varright =function(s, N) {returnS.SUBSTR (-N); } varindex =function(s, find) {returnS.indexof (Find) + 1; } //Extended Prototyping Methods var_proto =Object.prototype; //caching, resolving Quick Find var_cache = {}; //extension Operators var_alias = [ /@/g, "_e.", /and/gi, "&&", /or/gi, "| |", /<>/g, "! =", /not/gi, "!", /([^=<>]) = ([^=]|$)/g, ' $1==$2 ' ]; var_rquote =/""/G; var_rquotetemp =/!~/G; //compiling var_complite =function(code) {returnEval ("0," +code); } //Convert extended symbols to standard JS symbols var_interpret =function(exp) {Exp= Exp.replace (_rquote, "!~"); vararr = Exp.split (' "'); varI, n =arr.length; varK =_alias.length; for(vari = 0; I < n; i + = 2) { vars =Arr[i]; for(varj = 0; J < K; J + = 2) { if(Index (S, _alias[j]) >-1) {s= S.replace (_alias[j], _alias[j + 1]); }} Arr[i]=s; } for(vari = 1; I < n; i + = 2) {Arr[i]= Arr[i].replace (_rquotetemp, ' \ \ ')); } returnArr.join (' "'); } //defining a modal function var_templ =function(_list) {var_ret = []; var_i =-1; for(var_kinch_list) { var_e =_list[_k]; if(_e! =_proto[_k]) { if($C) {_ret[++_i] =_e; } } } return_ret; }. toString (); //ways to extend Queries_proto. Query =function(exp) {if(!exp) { return []; } varfn =_cache[exp]; Try { if(!fn) { varCode =_interpret (exp); Code= _templ.replace ("$C", code); FN= _cache[exp] =_complite (code); } returnfn This); } Catch(e) {return []; } } varDotest =function () { varHeros = [ //name ============ attack ===== Anti-======= strength = Agility ===== Intelligence = ={name: ' Ice room witch ', dp:38, ap:1.3, Str:16, Dex:16, int:21}, {name:' Silent Warlock ', dp:39, ap:1.1, Str:17, Dex:16, int:21}, {name:' Naga Demon ', dp:51, ap:6.0, str:21, dex:21, int:18}, {name:' Bounty hunter ', dp:39, ap:4.0, Str:17, dex:21, int:16}, {name:' Poison Warlock ', dp:45, ap:3.1, str:18, dex:22, int:15}, {name:' Guardian of the Light ', dp:38, ap:1.1, Str:16, dex:15, int:22}, {name:' Alchemist ', dp:49, ap:0.6, str:25, Dex:11, int:25 } //... ]; varMatch = heros. Query (' @Str >20 and @Dex >20 '); Showresult (match[0]);</p>//Enquiry: The End of "Shi" //results: Silent Warlock, Poison Warlock, alchemist varMatch = heros. Query (' Right (@name, 1) = ' '); Showresult (match[0]); } functionShowresult (Result) {alert (Result.name+ "" + result. DP + "" + result. AP + "" + result. Str + "" + result. Dex + "" +result. INT); }
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=8180
For more information, refer to: http://www.softwhy.com/javascript/
JavaScript-implemented query JSON instance code