Revision 0020c077
Von Sven Schöling vor etwa 3 Jahren hinzugefügt
js/kivi.js | ||
---|---|---|
676 | 676 |
$input.prop('selectionStart', position); |
677 | 677 |
$input.prop('selectionEnd', position); |
678 | 678 |
}; |
679 |
|
|
680 |
ns.serialize = function(source, target = [], prefix, in_array = false) { |
|
681 |
let arr_prefix = first => in_array ? (first ? "[+]" : "[]") : ""; |
|
682 |
|
|
683 |
if (Array.isArray(source) ) { |
|
684 |
source.forEach(( val, i ) => { |
|
685 |
ns.serialize(val, target, prefix + arr_prefix(i == 0), true); |
|
686 |
}); |
|
687 |
} else if (typeof source === "object") { |
|
688 |
let first = true; |
|
689 |
for (let key in source) { |
|
690 |
ns.serialize(source[key], target, (prefix !== undefined ? prefix + arr_prefix(first) + "." : "") + key); |
|
691 |
first = false; |
|
692 |
} |
|
693 |
} else { |
|
694 |
target.push({ name: prefix + arr_prefix(false), value: source }); |
|
695 |
} |
|
696 |
|
|
697 |
return target; |
|
698 |
}; |
|
679 | 699 |
}); |
680 | 700 |
|
681 | 701 |
kivi = namespace('kivi'); |
Auch abrufbar als: Unified diff
kivi.serialize - javascript flatten