python列表到javascript数组

2024-09-30 03:24:06 发布

您现在位置:Python中文网/ 问答频道 /正文

也许你们专家的回答很快,但我遇到了一个有趣的挑战,我无法完全理解。在

我有一个python.psp文件,它包含一个listmylist[],它在运行时被填充,另一个javascript函数期望一个列表动态地创建一个表单对象,并在用户单击按钮时发送它。按钮是有原因的,因为它是运行时生成的表的一部分。每一行包含一组不同的项目,这些项目是从它自己的myList[]我想将rowsmyList[]列表传递给javascript函数,基本上是如果用户单击按钮的话。在

下面是我的一些代码来帮助说明:

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\upython的python服务器页面(PSP)

^{pr2}$

上传.psp期望列表中的四项….

谢谢你在这个问题上的帮助。在

-吉姆


Tags: 项目key函数代码用户form列表var
1条回答
网友
1楼 · 发布于 2024-09-30 03:24:06

试试这个:

<%
  import json
  myList['item1', 'item2', 'item3', 'item3']
%>

<input type="button" value="Upload" onclick="postCert('/support/upload.psp', <%= json.dumps(myList) %>, 'post');" />

相关问题 更多 >

    热门问题