1

Heiho:-)## 我在Cognos 11 报告中获得了一些文本元素/单例,以显示一些计算值。我用d3.js添加了一些JavaScript来可视化这些值。

我尝试使用document.getElementsByClassName()从文本元素中获取值。它可以在 HTML 编辑器中使用,但是当我在Cognos中的JavaScript中尝试它时却不行。我只是在我的警报消息中得到“未定义” 。我在Cognos中的文本元素有一个名为"fname"的类。当我在脚本中使用硬编码值时,脚本的其余部分可以工作并显示图表。

HTML 编辑器

<!DOCTYPE html>
<html>
<body>

<input class="fname" type="text" value="Michael">

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
  var x = document.getElementsByClassName("fname")[0].value;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

用于 Cognos 的 JavaScript

define(["http://d3js.org/d3.v4.min.js"], function (d3) {
"use strict";

function D3Chart()
{
};

D3Chart.prototype.draw = function( oControlHost )
{
    var fname = document.getElementsByClassName("fname")[0].value;
    window.alert(fname);
    //some code
};

D3Chart.prototype.setData = function( oControlHost, oDataStore)
{
};

return D3Chart;
});
4

0 回答 0