On Fri, Jan 22, 2010 at 12:33:15PM +0530, Anand Chitipothu wrote:
> >
> > 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:
Do you mean, removing it via Javascript?
>
> <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.
Yes, or maybe it should receive a parameter that defines its behaviour.
The default, IMO, should be to respect the numbers.
By the way, I just fixed a little bug in unflatten which wouldn't let it
work with other separators than '--'. I sent you a "pull request" via
github. I'm telling you here because this is the first time I use this
feature, and I'm not sure if the message arrived to you.
Thanks,
--
Pablo Antonio (AKA crazy2k)
http://www.pablo-a.com.ar/
--
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.