Revision 04b933fc
Von Sven Schöling vor fast 3 Jahren hinzugefügt
js/kivi.js | ||
---|---|---|
699 | 699 |
return kivi._shell_escape(elt); |
700 | 700 |
}).join(' '); |
701 | 701 |
}; |
702 |
|
|
703 |
ns.serialize = function(source, target = [], prefix, in_array = false) { |
|
704 |
let arr_prefix = first => in_array ? (first ? "[+]" : "[]") : ""; |
|
705 |
|
|
706 |
if (Array.isArray(source) ) { |
|
707 |
source.forEach(( val, i ) => { |
|
708 |
ns.serialize(val, target, prefix + arr_prefix(i == 0), true); |
|
709 |
}); |
|
710 |
} else if (typeof source === "object") { |
|
711 |
let first = true; |
|
712 |
for (let key in source) { |
|
713 |
ns.serialize(source[key], target, (prefix !== undefined ? prefix + arr_prefix(first) + "." : "") + key); |
|
714 |
first = false; |
|
715 |
} |
|
716 |
} else { |
|
717 |
target.push({ name: prefix + arr_prefix(false), value: source }); |
|
718 |
} |
|
719 |
|
|
720 |
return target; |
|
721 |
}; |
|
702 | 722 |
}); |
703 | 723 |
|
704 | 724 |
kivi = namespace('kivi'); |
Auch abrufbar als: Unified diff
kivi.serialize - javascript flatten