I had a friend cook up a variable function for a client site.
I would need to show the var func id “street”, “city”, “dateStart” etc
Is there an easy way to do this with custom code?
This is the script
var item = "";
function deepCopy(src) {
street = "";
city = "";
country = "";
dateStart = "";
dateEnd = "";
timeStart = "";
timeEnd = "";
let target = Array.isArray(src) ? [] : {};
for (let prop in src) {
let value = src[prop];
if (value && typeof value === 'object' && prop != 'date') {
target[prop] = deepCopy(value);
} else {
if (prop == "place") {
locationArr = value.split(",");
if (locationArr.length > 2) {
street = locationArr[0];
city = locationArr[1];
country = locationArr[2];
}
target["Street"] = street;
target["City"] = city;
target["Country"] = country;
}
if (prop == "date") {
if (typeof value==='object') {
dateStart = value[0];
tempVal = value[0].split(" ");
if (tempVal.length > 1) {
dateStart = tempVal[0];
timeStart = tempVal[1];
} else {
dateStart = value[0];
timeStart = "";
}
tempVal = value[0].split(" ");
if (tempVal.length > 1) {
dateEnd = tempVal[0];
timeEnd = tempVal[1];
} else {
dateEnd = value[1];
timeEnd = "";
}
}
target["DateStart"] = dateStart;
target["TimeStart"] = timeStart;
target["DateEnd"] = dateEnd;
target["TimeEnd"] = timeEnd;
}
target[prop] = value;
}
}
return target;
}
$.ajax({
dataType: "json",
url: "https://franconia-karlsruhe.corpshaus2.de/api/v1/open_events.json",
async: false,
success: function(data) {
item = deepCopy(data);
}
});
console.log(deepCopy(item));
Here is my site Read-Only: https://preview.webflow.com/preview/franconia?utm_medium=preview_link&utm_source=designer&utm_content=franconia&preview=0f6388d9597bcf89baa679b9f75a3eac&workflow=preview