【问题标题】:Oracle APEX | How to change select list value and Submit it dynamically甲骨文 APEX |如何更改选择列表值并动态提交
【发布时间】:2016-12-21 18:41:45
【问题描述】:

我有两个选择列表

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 中的选定值包含一个国家/地区的城市。

    select city_name as d, city_id as r 
    from cities 
    where country_id = :P4_country_id_B

一切顺利,没有任何问题。

但是

我使用 执行 PL/SQL 代码动态操作来更改这些列表的选定值,如下所示(例如):

: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). 

第一个选择的列表值会改变第二个列表永远不会改变。

注意事项:

  • 我使用 P4_country_id_B,P4_CITY_ID_B 作为 要提交的页面项目 进行动态操作。
    • 我不想提交页面而不是动态操作

请问在这种情况下如何更改列表值?

提前致谢。

【问题讨论】:

    标签: oracle plsql oracle-apex


    【解决方案1】:

    我认为这里有些混乱。我在下面的回答假设,根据您的问题,第一个列表名称是 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 保存了该列表的返回值。

    我不确定您要在这里实现什么。但我假设,您希望允许用户首先选择国家,然后基于此,您希望刷新城市列表以显示该特定国家的城市。如果是这种情况,则对P4_country_id_B 值更改使用动态操作,以刷新Cities_LOV 的值。您只需将P4_country_id_B 传递给该动态操作。

    更新

    在你更正问题的措辞后,答案是这样的:

    在您的子列表P4_CITY_ID_B 中,确保将选项Cascading LOV parent item(s) 设置为父列表P4_country_id_B。您不需要动态操作。子列表应在父列表更改时刷新。答案here,详细介绍了如何实现级联列表

    【讨论】:

    • 很抱歉在写这篇文章时有一些错误,但现在我已经纠正了它们并澄清了混乱。
    【解决方案2】:

    级联选择列表通过 ajax 刷新。
    更改选择列表 1,选择列表 2 将被刷新。
    您执行 plsql,这反过来将设置所涉及项目的值。两者都是选择列表,一个依赖于另一个。
    因此,虽然两者都将被设置,但第一个的更改将导致第二个被刷新。
    换句话说,你做得太快了。虽然有解决方案,但正确的方法有点复杂,我不会亲自在 DA 中构建它。

    您尚未指定如何或何时调用设置项目值的代码。所以在这里我将假设一个 DA 具有“执行 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回调”下新建一个进程,命名为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;
    

    这应该将所有内容联系在一起。

    【讨论】:

    • 非常感谢您的努力,但它对我不起作用,我认为这是因为代码必须在每件事之前为 country_id 列表设置一个值,因为city_id 列表完全取决于 country_id 列表的选定值。
    • 它是如何“不工作”的?如果你不澄清,我无能为力。您描述的原因是我在回答中给出的确切原因。我的观点正是:设置国家ID,让城市刷新,然后设置城市ID。你有js的问题吗? apex.oracle.com 上的一个简单示例页面,其中说明了问题,确实有助于在那里应用解决方案。
    • 它在 s JSON 中的位置 0 处返回意外的标记,你能看到这个吗! :这里是 apex.oracle.com apex.oracle.com/pls/apex/f?p=42153:2:105276779939013::::: 中的一个示例 用户名:sadammashaal@hotmail.com 密码:meshaal 架构:meshaal。非常感谢。
    • @SaddamMeshaal 我创建了一个已修复所有问题的复制页面:1) 选择器区分大小写! P3_DEP_LIST 而不是P3_dep_list 2) 你在回调过程中使用P3_EMP_ID,所以它必须在调用中提供,我是通过pageItems 这样做的 3) 在回调过程中捕获可能的错误并错误返回json,导致显示错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-09
    • 1970-01-01
    相关资源
    最近更新 更多