Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/426.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在新窗口中单击将javascript数组转换为html表_Javascript_Html - Fatal编程技术网

在新窗口中单击将javascript数组转换为html表

在新窗口中单击将javascript数组转换为html表,javascript,html,Javascript,Html,我正在创建数据可视化,我有一个按钮,它将执行JavaScript函数,并根据用户的选择从指定的数据列中提取前五行: getselection.onclick = function() { visual.Document.selection.getselection( "City", \\identifies the selection "Users", \\identifies the table ["Na

我正在创建数据可视化,我有一个按钮,它将执行JavaScript函数,并根据用户的选择从指定的数据列中提取前五行:

getselection.onclick = function()
{
visual.Document.selection.getselection(
"City",                        \\identifies the selection
"Users",                       \\identifies the table
["Name", "Phone", "Zipcode"],  \\identifies the columns
5,
function(args)
        {
            log(dump(args, "visual.Document.selection.getselection", 2));
        });
};
结果输出如下所示:

[Name]
0:  xxxxx
1:  xxxxx
2:  xxxxx

[Phone]
0:  xxxxx
1:  xxxxx
我想做的是在一个新窗口中显示用户选择的结果,该窗口在单击时打开。我看到了一些做类似事情的建议,但出于某种原因,我似乎无法让它们发挥作用。以下是我到目前为止的情况:

function getSelMarking() {
visual.Document.selection.getMarking(
    "city",
    "Users",
    ["Name", "phone", "Zipcode"],
    5,
    function(args) {
        var UserIDs=dump(args);



        HTMLstring='<HTML>\n';
        HTMLstring+='<HEAD>\n';
        HTMLstring+='<TITLE>New Document</TITLE>\n';
        HTMLstring+='</HEAD>\n';
        HTMLstring+='<BODY>\n';
        HTMLstring+='<P>Hello World</P>\n';
        HTMLstring+='<table>\n';
        HTMLstring+='<tr>\n';
        HTMLstring+='<td>'+UserIDs+'</td>\n';
        HTMLstring+='<td>'+UserIDs+'</td>\n';
        HTMLstring+='<td>'+UserIDs+'</td>\n';
        HTMLstring+='</tr>\n';
        HTMLstring+='</table>\n';
        HTMLstring+='</BODY>\n';
        HTMLstring+='</HTML>';
        newwindow=window.open();
        newdocument=newwindow.document;
        newdocument.write(HTMLstring);
        newdocument.close();
        }
    );
}
函数getSelMarking(){ visual.Document.selection.getMarking( “城市”, “用户”, [“姓名”、“电话”、“Zipcode”], 5. 函数(args){ var UserIDs=dump(args); HTMLstring='\n'; HTMLstring+='\n'; HTMLstring+=“新文档\n”; HTMLstring+='\n'; HTMLstring+='\n'; HTMLstring+='

你好,世界

\n'; HTMLstring+='\n'; HTMLstring+='\n'; HTMLstring+=''+用户ID+'\n'; HTMLstring+=''+用户ID+'\n'; HTMLstring+=''+用户ID+'\n'; HTMLstring+='\n'; HTMLstring+='\n'; HTMLstring+='\n'; HTMLstring+=''; newwindow=window.open(); newdocument=newwindow.document; newdocument.write(HTMLstring); newdocument.close(); } ); } 就我所知。我完全被困在这个问题上——也许我只是对函数如何工作没有很好的理解?不管怎样,谢谢你能在这里提供任何帮助的人

我忘了包括dump()函数的分解:

var dump = function(obj, name, indent, depth) {
if (depth > MAX_DUMP_DEPTH) {
    return indent + name + ": <Maximum Depth Reached>\n";
}

if (typeof(obj) == "object") {
    var child = null;
    var output = name + "\n";
    indent += "\t";
    for (var item in obj) {
         try {
            if (item.charAt(0) == '_')  {
                continue;
            }
            child = obj[item];
        } catch (e) {
            child = "<Unable to Evaluate>";
        }

        if (typeof child == "object") {
            output += dump(child, item, indent, depth + 1);
        } else if (typeof(child) == "function") {
            var functionName = String(child);
            functionName = functionName.substring(0, functionName.indexOf("{", 0) -     
10}
            output += "\t" + item + ": " + functionName + "\n";
        } else {
            var value = "";
            if (child == null) {
                value = "[null]";
            } else {
                value = child;
            }
            output += "\t" + item + ": " + value + "\n";
        }
    }
    return output + "\n";
} else {
    return obj;
}
};
var dump=函数(对象、名称、缩进、深度){
如果(深度>最大卸载深度){
返回缩进+名称+“:\n”;
}
if(类型(obj)=“对象”){
var child=null;
变量输出=名称+“\n”;
缩进+=“\t”;
用于(obj中的var项目){
试一试{
如果(项目字符(0)='\uu'){
持续
}
子项=对象[项目];
}捕获(e){
child=“”;
}
如果(子对象的类型=“对象”){
输出+=转储(子项、项、缩进、深度+1);
}else if(类型(子项)=“函数”){
var functionName=字符串(子级);
functionName=functionName.substring(0,functionName.indexOf(“{”,0)-
10}
输出+=“\t”+项+”:“+functionName+”\n”;
}否则{
var值=”;
if(child==null){
value=“[null]”;
}否则{
价值=儿童;
}
输出+=“\t”+项目+”:“+值+”\n”;
}
}
返回输出+“\n”;
}否则{
返回obj;
}
};

我找到了我自己问题的答案。这里的困难是因为我不了解javascript是如何处理数组的。对不起大家。

您使用的是未标记的库吗?什么是
可视的
对象?您的javascript控制台中是否有任何错误(如果你不知道这是什么,点击F12进入开发者工具)对不起,我应该把这个脚本包含在dump函数中,这是我的错误。我相信这是我唯一遗漏的东西,
visual
对象指的是数据可视化。我检查了控制台,没有发现任何错误。在我看来,至少这是我不知道怎么做的事情,不是一个技术问题错误。如果你认为我还应该找别的东西,请告诉我。