简体   繁体   English

使用javascript更改Spotfire文档属性值

[英]Change Spotfire Document Properties value using javascript

I want to Change the value assigned to a Document Property in spot fire. 我想在现场射击时更改分配给文档属性的值。 Lets say i have created a new document property called "Test1" as a string and assign it a value "a". 可以说我已经创建了一个新的文档属性“ Test1”作为字符串,并为其分配了值“ a”。 Is there are way to change this value using Javascript every time i load the spotfire dashboard ? 每次加载Spotfire仪表板时,是否可以使用Java脚本更改此值?

I'm unaware of a way to use JavaScript for this, but you can assign a string document property via custom expression (if it's a List Box) or run an IronPython script each time the value changes. 我不知道使用JavaScript的方式,但是您可以通过自定义表达式(如果是列表框)分配string文档属性,或者每次值更改时都运行IronPython脚本。 So, you could set the expression to the current date, datetimenow() and then every time it's loaded the IronPython script would fire. 因此,您可以将表达式设置为当前日期datetimenow() ,然后每次加载IronPython脚本时就会触发。 However, I don't see why you'd need the property control for this. 但是,我不明白为什么您需要为此进行属性控制。

I suppose it really depends on what you want the document property to be set to. 我想这真的取决于您希望将document属性设置为什么。 Is it data from your tables? 是您表格中的数据吗? Output from complex code? 从复杂代码输出? These are all things to consider. 这些都是要考虑的事情。

1) Create an input type property control using the Document Property you want to change. 1)使用要更改的文档属性创建输入类型属性控件。

2) Edit Html to assign parent element an id say "testInput". 2)编辑HTML,为父元素分配ID,例如“ testInput”。 And add the script as shown below in the Edit HTML window. 然后在“编辑HTML”窗口中添加脚本,如下所示。

<span id="testInput"><SpotfireControl id="7db34e6c423240f59fc99e6b80fa23ec" /></span>


<script>
$("#testInput input").val("after");
$("#testInput input").focus();
$("#testInput input").blur();
</script>

3) This script will change the document property value to "after" whenever you open a file. 3)每当您打开文件时,此脚本会将文档属性值更改为“ after”。

As you comment seemed to suggest, something you can do is write this code in Python and attach the script to an action control, ei a Link or a Button. 正如您的评论所暗示的,您可以做的就是用Python编写此代码,并将脚本附加到动作控件(即链接或按钮)上。 Something simple like: Document.Properties["Test1"] = newValue or even: Document.Properties[changingProperty] = newValue allowing the code to be more reusable. 一些简单的东西,例如: Document.Properties["Test1"] = newValue或什至: Document.Properties[changingProperty] = newValue使代码更可重用。

Then you insert Javascript into the Text Area as well to the effect of: $("#VeryLongSpotfireControlID").click(); 然后,将Javascript插入到文本区域中,以达到以下效果: $("#VeryLongSpotfireControlID").click();

Which should simulate clicking on action control, which in turn triggers the Python script to update the value. 哪个应该模拟动作控件上的点击,然后依次触发Python脚本来更新值。 Just be careful not to use this approach when it would result in reloading the text area HTML, as this will re-trigger the Javascript, thus creating an endless loop. 请小心不要使用这种方法,因为它会导致重新加载文本区域HTML,因为这将重新触发Javascript,从而造成无限循环。

I believe I have found a possible solution/work-around for the issue, entirely based on pure JavaScript (since TIBCO removed jQuery starting from Spotfire X). 我相信我已经找到了一个可能的解决方案/解决方案,完全基于纯JavaScript(因为TIBCO从Spotfire X开始删除了jQuery)。 The solution is to force a simulated Enter Keystroke while focusing the input box to trigger updating the Document Property. 解决方案是在聚焦输入框时触发模拟的Enter键,以触发更新文档属性。 (No data function and R needed) (无需数据功能和R)

HTML (SpotfireControl Element is an single line input-box for a Doc. Prop.): HTML(SpotfireControl元素是文档属性的单行输入框):

<div id="container"><SpotfireControl id="b8534f13dc62416db6d4eaab16030f5e" /></div>

JS (focus and blur might no longer be needed for this solution, but I'm still keeping them just in case): JS(此解决方案可能不再需要聚焦和模糊处理,但是我还是以防万一)

const inputConfirmationEvent = new KeyboardEvent("keypress", {
    keyCode: 13,
    bubbles: true,
    cancelable: false
});

var elem = document.querySelector("#container input");
elem.value = "stringValue";
elem.blur();
elem.focus();

document.querySelector("#container input").dispatchEvent(inputConfirmationEvent);

Hope it helps someone. 希望它可以帮助某人。

Best, Aaron 最好,亚伦

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM