Friday, May 28, 2010

Re: Having to rstrip the " [] " from the end of your Key when posted?

I accept this as normal now. I think, what I'll need to do if I'm
against stripping off the two characters, is simply putting the value
that serves as the key, directly into the array as the last element.
Simple enough.

So in views function:
It'll look like: request.POST["imthekeyval[]"] = ("someval",
"anotherval", "imthekeyval")

code:

for key in request.POST.getlist(key):
py_array = request.POST.getlist(key)

( py_array has all I need, no need to use the key which is
sporting the mutant "[]" growth at the end )


On May 28, 5:41 pm, pyfreak <sitecontac...@gmail.com> wrote:
> I'm having to, in Javascript, create a dictionary ( my_dict = {} ),
> then put in some Arrays.
>
>  my_dict["stringkey"] = Array("hey","hey1")
>  my_dict["stringkey1"] = Array("more","stuff")
>
> In the views function:
>
>     for key in request.POST:
>              prop_rec = request.POST.getlist(key)
>
>  The Python var, "prop_rec"  has the array contents that I'm
> expecting.
>
>  However, I also need to use "key".  But when I'm sending over stuff
> from javascript like above,
> the key has a "[]" tacked on the end of it, like "stringkey[]"
>
> If I code the normal in js:
>   my_dict["stringkey"] = "1",
>         then  if I do a print key in the views function, I don't get
> the brackets at the end
>
> So just wondering if that's normal.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment