ruby on rails - How to loop a json object's value using jquery ajax -


how loop through json data value contains html returned ajax call in jquery.example : want count number of li tags in below data specified class.

i need count number of li tags have coded_false , itcoded_false together.also, should able count li tags individual counts .as in, count number of itcoded_true, coded_true,coded_false,itcoded_false.

please me out . thanks!

 $.ajax({      url: root_path + "/test_descriptions/get_table_counts/" + id + '.json',      type: "get",      data: {          dataset_id: dataset_id      },      success: function (data) {          data2 = data.coded_true       }   });   } 

below value of json data controller.

{"coded_true":"<ul class='tp_info'></ul><ul class='tp_info'><li class='coded_true itcoded_false'>the sldodialogs.responseoptimization.optimizationsection.optimize\n         method solves optimization problem using parallel pool if the\n         useparallel option set 'always'.</li></ul><ul class='tp_info'><li class='coded_true itcoded_false'>the optimize command throws warning if useparallel option\n         set 'always' , optimizedmodel option empty.</li><li class='coded_true itcoded_false'>the optimize command throws error if useparallel option is\n         set 'always', optimizemodel options not empty, , model\n         specified optimizemodel option dirty.</li></ul><ul class='tp_info'><li class='coded_true itcoded_false'>the patternsearch solver uses parallel pool evaluate\n         candidate solutions in poll , search sets.</li><li class='coded_true itcoded_true'>the cpu consumption on workers should increase @ same rate\n         master cpu when optimization runs patternsearch solver in the\n         parallel mode. g860087</li></ul><ul class='tp_info'><li class='coded_true itcoded_false'>the initparallel method protected method.</li><li class='coded_true itcoded_false'>the initparallel method checks simulink models that\n         used during optimization , makes sure not dirty.</li><li class='coded_true itcoded_false'>the initparallel method initializes parallel pool workers by\n         calling parallelsim.setupworkers utility. options.optimizedmodel\n         , options.parallelpathdependencies properties passed to\n         setupworkers.</li><li class='coded_true itcoded_false'>the finishparallel method protected method.</li><li class='coded_true itcoded_false'>the finishparallel method restores matlabpool workers by\n         calling parallelsim.cleanupworkers utility.</li></ul> 

if want use jquery count number of li containing in text can in following way:

var somehtml = data2 = data.coded_true;

$(somehtml).find("li").length;

consider jquery( html [, ownerdocument ] )


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -