[Solved] JSON Object to Jquery select array [closed]


You can use Array.prototype.map() function.

var o = {"tuple":[{"old":{"MST_VAS_TYPE":{"MST_VAS_TYPE_ID":"VAS_1000","VAS_TYPE_NAME":"AMC","VAS_TYPE_DESC":"Annual Maintenance Contract","CREATED_ON":null,"CREATED_BY":null,"MODIFIED_ON":null,"MODIFIED_BY":null,"@xmlns":"http://services.vw.com/lpms/1.0/wsapp"}},"@xmlns":"http://services.vw.com/lpms/1.0/wsapp"},{"old":{"MST_VAS_TYPE":{"MST_VAS_TYPE_ID":"VAS_1001","VAS_TYPE_NAME":"EW","VAS_TYPE_DESC":"Extended Warranty","CREATED_ON":null,"CREATED_BY":null,"MODIFIED_ON":null,"MODIFIED_BY":null,"@xmlns":"http://services.vw.com/lpms/1.0/wsapp"}},"@xmlns":"http://services.vw.com/lpms/1.0/wsapp"},{"old":{"MST_VAS_TYPE":{"MST_VAS_TYPE_ID":"VAS_1002","VAS_TYPE_NAME":"COUPON","VAS_TYPE_DESC":"Recall","CREATED_ON":null,"CREATED_BY":null,"MODIFIED_ON":null,"MODIFIED_BY":null,"@xmlns":"http://services.vw.com/lpms/1.0/wsapp"}},"@xmlns":"http://services.vw.com/lpms/1.0/wsapp"}],"@xmlns:SOAP":"http://schemas.xmlsoap.org/soap/envelope/","@xmlns":"http://services.vw.com/lpms/1.0/wsapp"};
a= o.tuple.map(function(val){
  var inner = val['old']['MST_VAS_TYPE'];
  var ret = {};
  ret[inner["MST_VAS_TYPE_ID"]] = inner['VAS_TYPE_NAME'];
  return ret;
})
sel = document.createElement("select");
document.body.appendChild(sel);
for (var index in a) {
  obj = a[index];
  for (var prop in obj){
    option = document.createElement("option");
    option.text = obj[prop];
    option.value = prop;
    sel.appendChild(option);
  }
}
//console.log(a);

2

solved JSON Object to Jquery select array [closed]