甲骨文顶点 |如何更改 select 列表值并动态提交
Oracle APEX | How to change select list value and Submit it dynamically
我有两个 select 列表
1.第一个 P4_country_id_B 包含国家名称
select country_name as d, country_id as r
from countries
2。第二个 P4_CITY_ID_B 包含一个国家/地区的城市,该城市基于 P4_CITY_ID_B 中的 selected 值。
select city_name as d, city_id as r
from cities
where country_id = :P4_country_id_B
一切顺利,没有任何问题。
但是
我使用 执行 PL/SQL 代码动态操作 来更改这些列表的 selected 值,如下所示(例如):
:P4_country_id_B:=country_returned_value;
:P4_CITY_ID_B:=city_returned_value;
哪里
country_returned_value : is a one value of countries list values for example (USA)
city_returned_value : is a one value of cities list values for example (NewYourk).
第一个 selected 列表值改变 但 第二个列表永远不会改变。
备注:
- 我使用 P4_country_id_B、P4_CITY_ID_B 作为 要提交的页面项目 进行动态操作。
- 我不想提交页面而不是动态操作
在这种情况下如何更改列表值?
提前致谢。
我认为这里有些混乱。根据您的问题,我在下面的回答假设第一个列表名称是 P4_country_id_B
,第二个列表名称是 Cities_LOV
。如果不是这种情况,请澄清。
您的第一个列表名为 P4_country_id_B
,您通过以下语句将其分配给 自身:
:P4_country_id_B:=country_returned_value;
所以基本上,什么都没有改变,P4_country_id_B
的值是列表 P4_country_id_B
的返回值,不需要任何赋值。请注意,我不清楚 country_returned_value
是什么,因为 P4_country_id_B
保存返回值。
其次,您有一个名为 Cities_LOV
的列表,您通过以下语句将返回值分配给 P4_CITY_ID_B
页面项:
:P4_CITY_ID_B:=returned_city_value;
同样,我不确定 returned_city_value
是什么,因为 Cities_LOV
包含该列表的返回值。
我不确定你想在这里达到什么目的。但我假设,您希望首先允许用户 select 国家/地区,然后基于此,您希望刷新城市列表以显示该特定国家/地区的城市。如果是这种情况,则对 P4_country_id_B
值更改使用动态操作,以刷新 Cities_LOV
的值。您只需要将 P4_country_id_B
传递给该动态操作。
更新
改正问题的措辞后,答案将是这样的:
在您的子列表 P4_CITY_ID_B
中,确保将选项 Cascading LOV parent item(s)
设置为父列表 P4_country_id_B
。您不需要动态操作。子列表应在父列表更改时刷新。答案here,详细介绍了如何实现级联列表
级联 select 列表通过 ajax 刷新。
更改select列表1,select列表2将被刷新。
您执行 plsql,它又会设置所涉及项目的值。两者都是 select 列表,并且一个依赖于另一个。
因此,虽然两者都将被设置,但第一个的更改将导致第二个被刷新。
换句话说,你做得太快了。虽然有解决方案,但正确的方法有点复杂,我不会亲自在 DA 中构建它。
您没有指定如何或何时调用设置项目值的代码。所以这里我假设一个 DA 的动作类型为 "Execute JavaScript"(例如)
// perform a call to the ajax callback process to get the country and city id
// there are several ways to provide values to the process if necessary.
// for example through x01, which can be used in the proces like
// apex_application.g_x01
apex.server.process('GET_COUNTRY_DEFAULTS', {x01:""}).done(function(data){
// process returns JSON which contains 2 properties: country_id and city_id
// data.country_id
// data.city_id
// bind a ONE-TIME handler to the after refresh event of the city
// cascading LOVs fire the before and after refresh events like any other
// refreshable element in apex
// a one time handler since the values are different each time this code will
// execute
apex.jQuery("#Px_CITY_ID").one("apexafterrefresh",function(){
// after refresh of the list, attempt to set the value of the list to the
// value retrieved earlier
apex.item(this).setValue(data.city_id);
});
// finally, set the value of the country. Doing this will also trigger the
// refresh of dependent elements
apex.item('Px_CITY_ID').setValue(data.country_id);
// since a handler has been bound, the refresh will occur, the after refresh
// triggers, and the value will be set properly
});
最后在"AJAX Callback"下的页面新建一个进程,命名为GET_COUNTRY_DEFAULTS
DECLARE
l_country_id NUMBER;
l_city_id NUMBER;
BEGIN
l_country_id := 8;
l_city_id := 789;
htp.p('{"country_id":'||l_country_id||',"city_id":'||l_city_id||'}');
EXCEPTION WHEN OTHERS THEN
-- returning an error while using apex.server.process will prompt the user
-- with the error and halt further processing
htp.p('{"error":"'||sqlerrm||'"}');
END;
这应该将所有内容联系在一起。
我有两个 select 列表
1.第一个 P4_country_id_B 包含国家名称
select country_name as d, country_id as r
from countries
2。第二个 P4_CITY_ID_B 包含一个国家/地区的城市,该城市基于 P4_CITY_ID_B 中的 selected 值。
select city_name as d, city_id as r
from cities
where country_id = :P4_country_id_B
一切顺利,没有任何问题。
但是
我使用 执行 PL/SQL 代码动态操作 来更改这些列表的 selected 值,如下所示(例如):
:P4_country_id_B:=country_returned_value;
:P4_CITY_ID_B:=city_returned_value;
哪里
country_returned_value : is a one value of countries list values for example (USA)
city_returned_value : is a one value of cities list values for example (NewYourk).
第一个 selected 列表值改变 但 第二个列表永远不会改变。
备注:
- 我使用 P4_country_id_B、P4_CITY_ID_B 作为 要提交的页面项目 进行动态操作。
- 我不想提交页面而不是动态操作
在这种情况下如何更改列表值?
提前致谢。
我认为这里有些混乱。根据您的问题,我在下面的回答假设第一个列表名称是 P4_country_id_B
,第二个列表名称是 Cities_LOV
。如果不是这种情况,请澄清。
您的第一个列表名为 P4_country_id_B
,您通过以下语句将其分配给 自身:
:P4_country_id_B:=country_returned_value;
所以基本上,什么都没有改变,P4_country_id_B
的值是列表 P4_country_id_B
的返回值,不需要任何赋值。请注意,我不清楚 country_returned_value
是什么,因为 P4_country_id_B
保存返回值。
其次,您有一个名为 Cities_LOV
的列表,您通过以下语句将返回值分配给 P4_CITY_ID_B
页面项:
:P4_CITY_ID_B:=returned_city_value;
同样,我不确定 returned_city_value
是什么,因为 Cities_LOV
包含该列表的返回值。
我不确定你想在这里达到什么目的。但我假设,您希望首先允许用户 select 国家/地区,然后基于此,您希望刷新城市列表以显示该特定国家/地区的城市。如果是这种情况,则对 P4_country_id_B
值更改使用动态操作,以刷新 Cities_LOV
的值。您只需要将 P4_country_id_B
传递给该动态操作。
更新
改正问题的措辞后,答案将是这样的:
在您的子列表 P4_CITY_ID_B
中,确保将选项 Cascading LOV parent item(s)
设置为父列表 P4_country_id_B
。您不需要动态操作。子列表应在父列表更改时刷新。答案here,详细介绍了如何实现级联列表
级联 select 列表通过 ajax 刷新。
更改select列表1,select列表2将被刷新。
您执行 plsql,它又会设置所涉及项目的值。两者都是 select 列表,并且一个依赖于另一个。
因此,虽然两者都将被设置,但第一个的更改将导致第二个被刷新。
换句话说,你做得太快了。虽然有解决方案,但正确的方法有点复杂,我不会亲自在 DA 中构建它。
您没有指定如何或何时调用设置项目值的代码。所以这里我假设一个 DA 的动作类型为 "Execute JavaScript"(例如)
// perform a call to the ajax callback process to get the country and city id
// there are several ways to provide values to the process if necessary.
// for example through x01, which can be used in the proces like
// apex_application.g_x01
apex.server.process('GET_COUNTRY_DEFAULTS', {x01:""}).done(function(data){
// process returns JSON which contains 2 properties: country_id and city_id
// data.country_id
// data.city_id
// bind a ONE-TIME handler to the after refresh event of the city
// cascading LOVs fire the before and after refresh events like any other
// refreshable element in apex
// a one time handler since the values are different each time this code will
// execute
apex.jQuery("#Px_CITY_ID").one("apexafterrefresh",function(){
// after refresh of the list, attempt to set the value of the list to the
// value retrieved earlier
apex.item(this).setValue(data.city_id);
});
// finally, set the value of the country. Doing this will also trigger the
// refresh of dependent elements
apex.item('Px_CITY_ID').setValue(data.country_id);
// since a handler has been bound, the refresh will occur, the after refresh
// triggers, and the value will be set properly
});
最后在"AJAX Callback"下的页面新建一个进程,命名为GET_COUNTRY_DEFAULTS
DECLARE
l_country_id NUMBER;
l_city_id NUMBER;
BEGIN
l_country_id := 8;
l_city_id := 789;
htp.p('{"country_id":'||l_country_id||',"city_id":'||l_city_id||'}');
EXCEPTION WHEN OTHERS THEN
-- returning an error while using apex.server.process will prompt the user
-- with the error and halt further processing
htp.p('{"error":"'||sqlerrm||'"}');
END;
这应该将所有内容联系在一起。