>
> For example, imagine I have an input whose name is "data--1--age". Then,
> I'd like to access its data as i["data"][1]["age"]. However, look what's
> unflatten's result:
>
> >>> unflatten({"data--1--age": "20"})
> <Storage {'data': [<Storage {'age': '20'}>]}>
>
> This is what I have to do to get that "20":
>
> >>> i = unflatten({"data--1--age": "20"})
> >>> i["data"][0]["age"]
> '20'
>
Let me explain why it is like that with an example. Lets say you have data
[{"name": "x"}, {"name": "y"}]. When you render it in html, it becomes:
<input type="text" name="data--0--name" value="x"/>
<input type="text" name="data--1--name" value="y"/>
If you remove x and add z, it becomes:
<input type="text" name="data--1--name" value="y"/>
<input type="text" name="data--2--name" value="z"/>
After saving the form, you get data as [{"name": "y"}, {"name": "z"}].
Yes, it is kind of misleading. What you expect as index 1 becomes index 0.
May be it should be modified to return [None, {"name": "y"}, {"name": "z"}]
and provide a separate function to trim Nones.
Anand
--
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/webpy?hl=en.