Hi all,
I have a small javascript function that attempts to call an exposed
Turbogears method expecting a Python list as an argument. The function
takes the array-like NodeList of checkboxes in a form and attempts to
send the values of the positively-checked boxes back to Turbogears.
(This is a bit kludgy, but I noticed I had to turn the array-like
NodeList object returned by the DOM into an actual array before I
could serialize it into JSON, so I use Mochikit's map() function to do
this. I welcome suggestions as to how to better accomplish this task.)
My problem is that the array does not get properly deserialized into a
Python object and I end up . I am using Mochikit's loadJSONDoc method
to make the asynchronous call. In particular, I get an exception in
the map portion of the doSomething Turbogears method saying that '['
can't convert to an int.
Is there a clean way to automatically turn the data from this external
call to a Turbogears method into Python objects? The troubling
functions are below.
Thanks!
Mark
---
The javascript function is as follows:
function loadMatches() {
return loadJSONDoc("${tg.url('/')}", {tg_format: "json",
checkedBoxes : serializeJSON( map(function (x)
{return x.value;},
document.form.checkboxElements))});
}
The turbogears method looks like this:
@expose(format="json")
def doSomething(self, checkedBoxes):
# Turn checkedBoxes into a list of integers
intVals = map(int, checkedBoxes) # Fails here.
return dict(results=getMatches())
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---