jQuery反序列化表单
我正在使用 jQuery序列化序列化我的表单元素,并想反序列化它们.不幸的是找不到任何有效的jQuery反序列化器,有什么建议吗?
I am using jQuery Serialize to serialize my form elements and would like to deserialize them back. Unfortunately can't find any working jQuery deserializer, any suggestions?
一半的jQuery序列化为 param( ),因此反序列化查询字符串的内容中有一半将成为参数.不幸的是,我无法找到一个很好的独立脱模工具.现在,我建议获取 jQuery BBQ库并使用它.如果您不需要其他东西,可以将其删除.我读过Ben Alman(牛仔)计划将deparam提取到自己的模块中的某个地方.
Half of jQuery Serialize is param(), so half of something that deserializes a query string is going to be a deparam. Unfortunately I haven't been able to find a good standalone deparam. For now I recommend getting the jQuery BBQ library and using that. If you don't need the other stuff you can remove them. I read somewhere that Ben Alman (cowboy) planned to extract deparam into its own module.
对于反序列化的其余部分,您只需要遍历deparam返回的对象,并针对该对象中的每个键和值对,基于键选择表单元素,并将表单元素值设置为值.
For the rest of deserializing, you'll just need to loop through the object that deparam returns and for each key and value pair in the object, select the form element based on the key, and set the form elements value to the value.