Skip to content

Commit 8d5742e

Browse files
committed
handled nested array, fixed macek#45
1 parent 026541a commit 8d5742e

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

Diff for: dist/jquery.serialize-object.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: jquery.serialize-object.js

+14-9
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,25 @@
4848
}
4949

5050
function makeObject(root, value) {
51+
var keys = root.match(patterns.key), pushed = false, k, k2 = '';
5152

52-
var keys = root.match(patterns.key), k;
53+
function incrementPush(path, key) {
54+
pushes[path] = pushes[path] || {};
55+
if (pushes[path][key] === undefined) {
56+
pushes[path][key] = 0;
57+
}
58+
if (pushed) {
59+
return pushes[path][key];
60+
}
61+
pushed = true;
62+
return pushes[path][key]++;
63+
}
5364

5465
// nest, nest, ..., nest
5566
while ((k = keys.pop()) !== undefined) {
5667
// foo[]
5768
if (patterns.push.test(k)) {
58-
var idx = incrementPush(root.replace(/\[\]$/, ''));
69+
var idx = incrementPush(keys.join('.'), k2);
5970
value = build([], idx, value);
6071
}
6172

@@ -67,19 +78,13 @@
6778
// foo; foo[bar]
6879
else if (patterns.named.test(k)) {
6980
value = build({}, k, value);
81+
k2 = k;
7082
}
7183
}
7284

7385
return value;
7486
}
7587

76-
function incrementPush(key) {
77-
if (pushes[key] === undefined) {
78-
pushes[key] = 0;
79-
}
80-
return pushes[key]++;
81-
}
82-
8388
function encode(pair) {
8489
switch ($('[name="' + pair.name + '"]', $form).attr("type")) {
8590
case "checkbox":

0 commit comments

Comments
 (0)