2016-08-12 6 views
-1

Ich habe Oracle APEX 4. Ich erstellte ein Tabellenformular manuell (mit dem apex_item Paket). Es enthält drei Felder.Wie verwenden Sie dynamische Aktion in Tabellenform in Oracle Apex?

  • apex_application.g_f03: LOV (select name display, product_id return from products)
  • apex_application.g_f04: Textfeld "Preis"
  • apex_application.g_f05: Textfeld "Quantität".

Ich möchte den Preis des Produkts in F04 nach der Auswahl eines Produktnamens (... f03) sehen. Die SQL-Anweisung ist wie folgt:

select price from products where product_id = {..from f03}. 

Wie es mit dynamischer Aktion oder JavaScript-Funktion zu tun?

Antwort

1

OK, ich gebe Ihnen einen Hinweis, wie Sie Ihr Szenario implementieren.

Dinge, die Sie brauchen, sind, damit es funktioniert:

  • custom tabular für - Sie können es bereits
  • on demand process, die von Preis des Produkts fetchs db
  • dynamic action zu hören, wenn der Wert in f03
  • geändert

auf Anfrage Prozess

erstellen auf Anfrage Prozess namens getPrice mit Code folgenden

declare 
    v_price number; 
begin 
    select 
    price 
    into 
    v_price 
    from 
    products 
    where 
    product_id = apex_application.g_x01; 

    htp.p(v_price); 

exception 
    when others then 
    htp.p(SQLERRM); 
end; 

dynamische Aktion

Sie haben Ereignis Änderung auf jQuery-Selektor :input[name=f03] hört. Erstellen Sie dynamische Aktion mit True Action Execute JavaScript Code.

Innerhalb der richtigen Aktion müssen Sie Ajax Anruf an on demand process tun. Der Beispielcode (funktioniert) ist unten:

var 
    xhr2, 
    self = $(this.triggeringElement), 
    productId = self.val(), 
    row = self.closest('tr'); 

xhr = $.ajax({ 
    url:'wwv_flow.show', 
    type:'post', 
    dataType: 'text', 
    traditional: true, 
    data: { 
    p_request: "APPLICATION_PROCESS=getPrice", 
    p_flow_id: $v('pFlowId'), 
    p_flow_step_id: $v('pFlowStepId'), 
    p_instance: $v('pInstance'), 
    //p_arg_names: [ item_id ], 
    //p_arg_values: [ itemValue ], 
    x01: productId 
    }, 

    success: function(resultData, textStatus, ajaxObj){ 
    //do stuff after fetching product price 
    row.find(':input[name=f04]').val(resultData) 

    }, 

    error: function(jqXHR, textStatus, errorThrown){ 
    alert('Error occured while retrieving AJAX data: '+textStatus+"\n"+errorThrown); 
    } 
}); 

Setzen Sie die Sachen zusammen und Sie werden Antwort auf Ihre Frage haben.

Ps. Vergessen Sie nicht, die Antwort als hilfreich zu markieren, wenn es sich um eine Antwort auf Ihre Frage handelt.

Verwandte Themen