javascript - Editing an object in nested data structure -
i have data structure this:
var fieldtmp= [{ "countrydetails":[{ "countryname":"kerala", "jobdetails":[{ "requisitionid":"00020447961", "city":"kochi", "posteddate":"2016-12-18" },{ "requisitionid":"26103", "city":"trivandrum", "posteddate":"2016-12-12" },{ "requisitionid":"26077", "city":"alappey", "posteddate":"2016-10-09" },{ "requisitionid":"00020774701", "city":"kottayam", "posteddate":"2016-06-12" },{ "requisitionid":"26078", "city":"adoor", "posteddate":"2016-05-19"}] }, "countryname":"madras", "jobdetails":[{ "requisitionid":"0025456", "city":"chennai", "posteddate":"2017-06-05" },{ "requisitionid":"69847562", "city":"adyar", "posteddate":"2016-10-14"}] }, {"countryname":"tamil nadu", "jobdetails":[{ "requisitionid":"00020550501", "city":"chennai", "posteddate":"2016-12-18" },{ "requisitionid":"00020786022", "city":"kovai", "posteddate":"2016-09-01" },{ "requisitionid":"00020786071", "city":"trichy", "posteddate":"2016-04-10"}] }] }]
my requirement is, need add job details under madras tamil nadu , need sort data based on 1 property -posteddate. result should like,
var fieldtmp= [{ "countrydetails":[{ "countryname":"kerala", "jobdetails":[{ "requisitionid":"00020447961", "city":"kochi", "posteddate":"2016-12-18" },{ "requisitionid":"26103", "city":"trivandrum", "posteddate":"2016-12-12" },{ "requisitionid":"26077", "city":"alappey", "posteddate":"2016-10-09" },{ "requisitionid":"00020774701", "city":"kottayam", "posteddate":"2016-06-12" },{ "requisitionid":"26078", "city":"adoor", "posteddate":"2016-05-19"}] }, {"countryname":"tamil nadu", "jobdetails":[{ "requisitionid":"0025456", "city":"chennai", "posteddate":"2017-06-05" },{ "requisitionid":"00020550501", "city":"chennai", "posteddate":"2016-12-18" },{ "requisitionid":"69847562", "city":"adyar", "posteddate":"2016-10-14" },{ "requisitionid":"00020786022", "city":"kovai", "posteddate":"2016-09-01" },{ "requisitionid":"00020786071", "city":"trichy", "posteddate":"2016-04-10"}] }] }]
i tried extract madras data , add under tamil nadu. nothing working. know how extract single or multiple value json object. need edit json , sort it. able it.
i got solution. when countryname "tamil nadu" , "madras",i extracted data , saved in new array using below code.
function mergingbothstatedetails(jsonjobdetails){ for(var j=0;j<jsonjobdetails.length;j++) { newtmprecord.push({"requisitionid":jsonjobdetails[j].requisitionid, "posteddate":jsonjobdetails[j].posteddate, "city":jsonjobdetails[j].city}); } }
here newtmprecord array , universal variable
for sorting used below codes
function sortnewlist(){ newtmprecord.sort(function(a, b){ // sort object retirement date var datea=new date(a.posteddate), dateb=new date(b.posteddate) return dateb-datea //sort date descending }); }
Comments
Post a Comment