Comments (2)
When it comes to creating arrays of objects that have more than one field, you
have no other choice but to specify the array indexes for the objects that the
fields belong to.
Hopefully a simple demonstration makes that explantion a little more clear
<input name="hello[0][a]" value="1">
<input name="hello[0][b]" value="2">
Output
{
hello: [ {a: 1, b: 2} ]
}
If we don't specify the 0
index, watch what happens
<input name="hello[][a]" value="1">
<input name="hello[][b]" value="2">
Output
{
hello : [ {a: 1}, {b: 2} ]
}
Notice we have 2 objects created in the array instead of the desired 1.
Now let's take a look at how we'd format the fields for your entire form to get
the object you're looking for
<input name="character[0][male]">
<input name="character[0][female]">
<input name="character[0][result]">
<input name="character[0][itinerary][0][activity]">
<input name="character[0][itinerary][0][lat]">
<input name="character[0][itinerary][0][long]">
<input name="character[0][itinerary][1][activity]">
<input name="character[0][itinerary][1][lat]">
<input name="character[0][itinerary][1][long]">
<input name="character[0][itinerary][2][activity]">
<input name="character[0][itinerary][2][lat]">
<input name="character[0][itinerary][2][long]">
Now you're much closer to the object you're looking for.
However, I notice you're looking for string
and number
serialization. This
is not possible with the current version of jquery-serialize-object.
I'm currently working on getting the plugin up to spec of the W3C Draft
Specification for HTML JSON form submissions. After this is implemented,
jquery-serialize-plugin will take the type
of your <input>
elements into
account.
Serialize strings
<input type="text">
Serialize numbers
<input type="number">
Serialize boolean
<input type="checkbox">
If you have any more questions about this, let me know and I'll try to help.
from jquery-serialize-object.
Closing this issue. If you have other questions, we can always re-open it.
from jquery-serialize-object.
Related Issues (20)
- Parse files?
- Parse bool false? HOT 1
- Make array for single item/value of input box. HOT 1
- serializeObject() ignoring radio and checkbox inputs HOT 1
- serializeArray 's problem HOT 1
- NPM usage HOT 1
- 可否进行反序列操作呢
- Double key value pairs supported? HOT 2
- ~~Not~~ work if name has many '_'
- Not working correctly with certain elements HOT 1
- Not serialising values with "-" in name
- How to convert Complex forms ? HOT 1
- Does not cature multiple checkbox inputs
- how to take some values as integers
- Unwanted conversion of select box values from string to Infinity
- module "jquery" not found HOT 1
- Undefined 'serializeObject' in jQuery
- Does not grab multi-select options HOT 1
- Merge PR
- Initialize form values from object
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jquery-serialize-object.