Skip to content

Commit 9d13a7f

Browse files
committed
v0.3 release, Support for deJSONification added.
1 parent 5b47a9e commit 9d13a7f

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

dist/jquery.jsonify-0.2.min.js

-1
This file was deleted.

dist/jquery.jsonify-0.3.min.js

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

src/jsonify.js

+27-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
(function($) {
2-
$.fn.jsonify = function(options) {
3-
var settings = $.extend({
4-
stringify : false
5-
}, options);
6-
var json = {};
7-
$.each(this.serializeArray(), function() {
8-
if (json[this.name]) {
9-
if (!json[this.name].push)
10-
json[this.name] = [json[this.name]];
11-
json[this.name].push(this.value || '');
12-
} else
13-
json[this.name] = this.value || '';
14-
});
15-
if(settings.stringify)
16-
return JSON.stringify(json);
17-
else
18-
return json;
19-
};
2+
$.fn.jsonify = function(options) {
3+
var settings = $.extend({
4+
stringify : false
5+
}, options);
6+
var json = {};
7+
$.each(this.serializeArray(), function() {
8+
if (json[this.name]) {
9+
if (!json[this.name].push)
10+
json[this.name] = [json[this.name]];
11+
json[this.name].push(this.value || '');
12+
} else
13+
json[this.name] = this.value || '';
14+
});
15+
if(settings.stringify)
16+
return JSON.stringify(json);
17+
else
18+
return json;
19+
};
20+
21+
$.fn.dejsonify = function(data) {
22+
if (typeof data === 'string')
23+
data = JSON.parse(data);
24+
25+
$.each(this.find('*[name]'), function() {
26+
$(this).val(data[$(this).attr('name')]);
27+
});
28+
};
2029
})(jQuery);

0 commit comments

Comments
 (0)