{"id":247,"date":"2009-10-25T01:49:01","date_gmt":"2009-10-25T00:49:01","guid":{"rendered":"http:\/\/www.xcep.net\/blog\/?p=247"},"modified":"2009-10-25T01:49:22","modified_gmt":"2009-10-25T00:49:22","slug":"jquery-serialize-list-plugin","status":"publish","type":"post","link":"https:\/\/www.xcep.net\/blog\/jquery-serialize-list-plugin\/","title":{"rendered":"[jQuery] Serialize List Plugin"},"content":{"rendered":"<p>Mike\u00a0Botsko hat ein nettes Plugin f\u00fcr jQuery geschrieben, mit dem eine unordered list &lt;ul&gt; &#8222;serialisiert&#8220; werden kann, um sie dann mit PHP o.\u00e4. weiterverarbeiten zu k\u00f6nnen.<br \/>\nDer Quelltext des Plugins sieht wie folgt aus:<\/p>\n<pre lang=\"javascript\">(function($){\r\n    $.fn.serializelist = function(options) {\r\n        \/**\r\n         * jQuery Serialize List\r\n         * Copyright (c) 2009 Mike Botsko, Botsko.net LLC\r\n         * Licensed under the MIT (http:\/\/www.opensource.org\/licenses\/mit-license.php)\r\n         * Copyright notice and license must remain intact for legal use\r\n         * Version 1\r\n         *\r\n         * Serialize an unordered or ordered list item. Optional ability\r\n         * to determine which attributes are included. The serialization\r\n         * will be read by PHP as a multidimensional array which you may\r\n         * use for saving state.\r\n         *\/\r\n\r\n        \/\/ Extend the configuration options with user-provided\r\n        var defaults = {\r\n            prepend: 'ul',\r\n            is_child: false,\r\n            attributes: ['id', 'class']\r\n        };\r\n        var opts = $.extend(defaults, options);\r\n        var serialStr     = '';\r\n\r\n        if(!opts.is_child){ opts.prepend = '&amp;'+opts.prepend; }\r\n\r\n        \/\/ Begin the core plugin\r\n        this.each(function() {\r\n            var ul_obj = this;\r\n\r\n            var li_count     = 0;\r\n            $(this).children().each(function(){\r\n\r\n                for(att in opts.attributes){\r\n                    serialStr += opts.prepend+'['+li_count+']['+opts.attributes[att]+']='+$(this).attr(opts.attributes[att]);\r\n                }\r\n\r\n                \/\/ append any children elements\r\n                var child_base = opts.prepend+'['+li_count+'][children]';\r\n                $(this).children().each(function(){\r\n                    if(this.tagName == 'UL' || this.tagName == 'OL'){\r\n                        serialStr += $(this).serializelist({'prepend': child_base, 'is_child': true});\r\n                    }\r\n                });\r\n                li_count++;\r\n            });\r\n        });\r\n        return(serialStr);\r\n    };\r\n})(jQuery);<\/pre>\n<p>Der Aufruf erfolgt \u00fcber folgenden Befehl:<\/p>\n<pre lang=\"javascript\">$(document).ready(function(){\r\n    $('ul').serializelist();\r\n});<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Mike\u00a0Botsko hat ein nettes Plugin f\u00fcr jQuery geschrieben, mit dem eine unordered list &lt;ul&gt; &#8222;serialisiert&#8220; werden kann, um sie dann mit PHP o.\u00e4. weiterverarbeiten zu k\u00f6nnen. Der Quelltext des Plugins sieht wie folgt aus: (function($){ $.fn.serializelist = function(options) { \/** * jQuery Serialize List * Copyright (c) 2009 Mike Botsko, Botsko.net LLC * Licensed under [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[22,266,67,208,265,267],"_links":{"self":[{"href":"https:\/\/www.xcep.net\/blog\/wp-json\/wp\/v2\/posts\/247"}],"collection":[{"href":"https:\/\/www.xcep.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xcep.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xcep.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xcep.net\/blog\/wp-json\/wp\/v2\/comments?post=247"}],"version-history":[{"count":2,"href":"https:\/\/www.xcep.net\/blog\/wp-json\/wp\/v2\/posts\/247\/revisions"}],"predecessor-version":[{"id":249,"href":"https:\/\/www.xcep.net\/blog\/wp-json\/wp\/v2\/posts\/247\/revisions\/249"}],"wp:attachment":[{"href":"https:\/\/www.xcep.net\/blog\/wp-json\/wp\/v2\/media?parent=247"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xcep.net\/blog\/wp-json\/wp\/v2\/categories?post=247"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xcep.net\/blog\/wp-json\/wp\/v2\/tags?post=247"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}