How to extend a JSON array in Jquery

Suppose you get a JSON  Object like this

var optionsoptions;
 $.getJSON("relaytemplateattributes.json" , function(result){
optionsoptions=result.optionsoptions;
 });

/*JSON LIST FORMAT*/
{"optionsoptions":[{"OPTIONID":-1,"COMBOITEM":"---SELECT--"},{"OPTIONID":1,"COMBOITEM":"-3U0Comp"},
{"OPTIONID":1,"COMBOITEM":""},{"OPTIONID":1,"COMBOITEM":"-U2comp"},
{"OPTIONID":1,"COMBOITEM":"Ipol"},{"OPTIONID":1,"COMBOITEM":"-U2"},
{"OPTIONID":1,"COMBOITEM":"-3U0"},{"OPTIONID":1,"COMBOITEM":"Dual"},
{"OPTIONID":2,"COMBOITEM":"0 deg"},{"OPTIONID":2,"COMBOITEM":"180 deg"}
{"OPTIONID":3,"COMBOITEM":"1 out of 3"},{"OPTIONID":3,"COMBOITEM":"2 out of 3"},
{"OPTIONID":3,"COMBOITEM":"3 out of 3"},{"OPTIONID":4,"COMBOITEM":"4"},
{"OPTIONID":4,"COMBOITEM":"1"},{"OPTIONID":4,"COMBOITEM":"2"},
{"OPTIONID":4,"COMBOITEM":"3"},{"OPTIONID":4,"COMBOITEM":"5"},
{"OPTIONID":5,"COMBOITEM":"2 out of 3"}}

/*JSON LIST FORMAT*/
if you want to append to new value to optionsoptions Object you can extend the optionsoptions Object in jquery.


 var object3 = {
    "OPTIONID":newoptionName,
    "COMBOITEM": $("#newoptionValue3").val()
    };
    $.extend( optionsoptions, object3);

Comments

Post a Comment

Popular posts from this blog

defining functions clojure

Integrating Struts2 with Spring Security using Custom Login Form