【发布时间】:2017-05-30 16:39:37
【问题描述】:
这是我输入的 Json 数据文件的一部分:
{
"id": "ns=2:s=Configured Tags",
"text": "Configured Tags",
"path": "Configured Tags",
"children": [
{
"id": "ns=2:s=[System]",
"text": "System",
"path": "Configured Tags/System",
"children": [
{
"id": "ns=2:s=[System]Gateway",
"text": "Gateway",
"path": "Configured Tags/System/Gateway",
"children": []
}]
}]
}
这里我有自定义字段 path,但我需要一些其他字段,例如 dataType 等。
我想返回一个来自自定义fields 的串联字符串,作为我表单的输入值。
这是我的表单和 jstree 脚本部分:
<form id="form" action="/opc_add_data" method="post">
<div id="tree"></div>
<br>
<button class="btn-flat inverse pull-right" name="submit" id="submit" onclick="return confirm('Are you sure?')" type="submit">Confirm</button>
</form>
$('#form').submit(function() {
var data = $('#tree').jstree(true).get_bottom_selected(true);
for(var count = 0; count < data.length; count++){
$(this).append('<input type="text" name="' + data[count]["id"] + '" value="' + data[count]["path"] + '" hidden/>');
}
return true;
});
我的表单过程的一部分(Python2.7):
for key in request.form.keys():
if key != "submit":
description.append(re.sub('[^a-zA-Z0-9 \n.]', '_', request.form.get(key)))
如果我尝试获取data[count]["id"] 和data[count]["text"],我会成功,因为text 和id 是the doc 中描述的字段。但是当我尝试自定义时,我得到"undefined" 作为值。
我的问题是:我真的可以做我想做的事吗,即以这种方式获取自定义字段data[count]["path"]?
【问题讨论】: