Pentaho - 如何获取所选组件的索引?
Pentaho - how to get the index of selected component?
我正在尝试使用 CDE Dashboard
中的 Select Component
获取所选元素的索引。
非常简单:
SELECT id, username FROM table1
-- this feeds the Select Component
我已将 "Value as ID" 设置为 FALSE
,因此下拉列表将显示 username
并将 return 中定义的 ID
Select Component
.
的 17=] 字段
我需要编写一些 JavaScript 代码来从所选选项中读取两个值(ID
和 username
),我已经尝试使用 this.selectedIndex
,但是它总是 returns -1
.
如果我可以获得索引,我可以遍历 resultSet
对象并获取所有列。
也尝试过 JQuery,但我不是专家,尽管我尝试过:
$( "#my_select_component" ).val()
但没用。
如果有更简单的方法来实现这一点,我将不胜感激并提供反馈。
我使用此代码获取下拉列表中所选项目的 id
:
function f(value) {
Dashboards.log(value);
return value;
}
代码放在我的Select Component
的Pre Change
属性(注意Pre Change
属性是Advanced Properties
视图的一部分CDE
)。
Pre Change
代码在组件更改之前触发。
我最终得到了这个:
在 my_select_component 的预更改中:
function f(){
$("#my_select_component").on("change", function() {
Dashboards.setParameter(
"my_parameter_to_update_titles",
$(this).find(":selected")[0].innerText
);
});
}
我正在尝试使用 CDE Dashboard
中的 Select Component
获取所选元素的索引。
非常简单:
SELECT id, username FROM table1
-- this feeds the Select Component
我已将 "Value as ID" 设置为 FALSE
,因此下拉列表将显示 username
并将 return 中定义的 ID
Select Component
.
我需要编写一些 JavaScript 代码来从所选选项中读取两个值(ID
和 username
),我已经尝试使用 this.selectedIndex
,但是它总是 returns -1
.
如果我可以获得索引,我可以遍历 resultSet
对象并获取所有列。
也尝试过 JQuery,但我不是专家,尽管我尝试过:
$( "#my_select_component" ).val()
但没用。
如果有更简单的方法来实现这一点,我将不胜感激并提供反馈。
我使用此代码获取下拉列表中所选项目的 id
:
function f(value) {
Dashboards.log(value);
return value;
}
代码放在我的Select Component
的Pre Change
属性(注意Pre Change
属性是Advanced Properties
视图的一部分CDE
)。
Pre Change
代码在组件更改之前触发。
我最终得到了这个:
在 my_select_component 的预更改中:
function f(){
$("#my_select_component").on("change", function() {
Dashboards.setParameter(
"my_parameter_to_update_titles",
$(this).find(":selected")[0].innerText
);
});
}