python 列表到 javascript 数组
可能是你们专家的快速回答,但我偶然发现了一个有趣的挑战,我无法理解它。
我有一个 python .psp 文件,其中包含一个在运行时填充的列表 mylist[] 和一个 javascript 函数,该函数期望列表动态创建表单对象并在用户单击按钮时发送它。该按钮是有原因的,因为它是在运行时生成的表的一部分。每行都包含从其自己的 myList[] 创建的一组不同的项目,基本上,如果用户单击按钮。
下面是我的一些代码来帮助说明:
Javascript:
function post(path, paramaters, method) {
method = method || "post";
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
for(var key in parameters){
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", parameters[key]);
form.appendChild(hiddenField);
}
//create form and submit
document.body.appendChild(form);
form.submit();
}
使用 mod_python upload.psp 的 python 服务器页面 (PSP)
<%
myList['item1', 'item2', 'item3', 'item3']
req.write(<input type="button" value="Upload" onclick="postCert(\'/support/upload.psp\', myList,\'post\');" />)
%>
需要列表中的四项......
感谢您在这方面的帮助。
-吉姆
Probably a quick answer from you experts, but i am stumbling upon a interesting challenge that I can't wrap my head around.
I have a python .psp file that contains both a list mylist[] which gets populated on runtime and a javascript function expecting a list to dynamically crreate a form object and send it when the user clicks a button. There is a reason for the button as it is part of a table that has been generated on runtime. Each row contains a different set of items created from it's own myList[] I would like to pass the rows myList[] list to the javascript function basically if the user clicks the button.
Here's some of my code to help illustrate:
Javascript:
function post(path, paramaters, method) {
method = method || "post";
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
for(var key in parameters){
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", parameters[key]);
form.appendChild(hiddenField);
}
//create form and submit
document.body.appendChild(form);
form.submit();
}
python Server Pages (PSP) using mod_python
<%
myList['item1', 'item2', 'item3', 'item3']
req.write(<input type="button" value="Upload" onclick="postCert(\'/support/upload.psp\', myList,\'post\');" />)
%>
upload.psp is expecting the the four items in the list....
Thanks for you help on this one.
-Jim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
Try this: