0

我正在创建数据可视化,我有一个按钮,它将执行 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

我想做的是在单击时打开的新窗口中的 HTML 表中显示用户选择的结果。我已经看到了做类似事情的建议,但由于某种原因,我似乎无法让它们工作。这是我到目前为止所拥有的:

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();
        }
    );
}

这就是我所得到的。我完全坚持这一点-也许我只是对这些功能的工作方式没有很好的了解?无论如何,感谢任何可以在这里提供任何类型帮助的人。

我忘了包括 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;
}
};
4

1 回答 1

-1

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

于 2014-02-01T01:45:26.023 回答