javascript - Parsing though JSON-data and getting one Object -
i getting simple json data structure phone numbers, fax numbers , mobile numbers in sapui5 application:
{ "teles": [ {"tele": "05312024040", "default": true}, {"tele": "017666254336", "default": false}, {"tele": "017666224336", "default": false} ], "faxs": [ {"fax":"053155599755", "default": true}, {"fax":"01548568745", "default": false} ], "mobils": [ {"mobil":"017655994816", "default": true}, {"mobil":"01548568745", "default": false} ] }
my goal loop/parse through data structure , number default, , put model name "tele-standard", "fax-standard" or "mobil-standard". should happen before displaying data, can put these textfields, editable:
i don't know @ how jquery, or sapui5 or javascript can reach goal. can maybe help?
results in new model should like:
{ "archived": "-", "nummer": "12", "anrede": "herr", "vorname": "osamah", "nachname": "al-doaiss", "tele-default": "05312024040", "fax-defaule": "053155599755", "mobil-default": "017655994816" }
tl;dr: have json arrays. want parse through them , default number. no idea how!
try this
1
var data = { "teles": [ {"tele": "05312024040", "default": true}, {"tele": "017666254336", "default": false}, {"tele": "017666224336", "default": false} ], "faxs": [ {"fax":"053155599755", "default": true}, {"fax":"01548568745", "default": false} ], "mobils": [ {"mobil":"017655994816", "default": true}, {"mobil":"01548568745", "default": false} ] }; var model = { "archived": "-", "nummer": "12", "anrede": "herr", "vorname": "osamah", "nachname": "al-doaiss" }; object.keys(data).foreach(function (key) { data[key].foreach(function (el) { var keys = object.keys(el), key = keys.join('-'); if (el.default && el.default === true && !model[key]) { model[keys.join('-')] = el[keys[0]]; } }); }); console.log(model);
2
var data = { "teles": [ {"tele": "05312024040", "default": true}, {"tele": "017666254336", "default": false}, {"tele": "017666224336", "default": false} ], "faxs": [ {"fax":"053155599755", "default": true}, {"fax":"01548568745", "default": false} ], "mobils": [ {"mobil":"017655994816", "default": true}, {"mobil":"01548568745", "default": false} ] }; var model = { "archived": "-", "nummer": "12", "anrede": "herr", "vorname": "osamah", "nachname": "al-doaiss" }; object.keys(data).foreach(function (key) { data[key].foreach(function (el) { var keys = object.keys(el), key = keys.join('-'); if (el.default && el.default === true && !model[key]) { model[key] = el[keys[0]]; } }); }); console.log(model);
Comments
Post a Comment