2016-08-12 41 views
-1

我有Oracle APEX 4.我手動創建了一個表格形式(使用apex_item包)。它包含三個字段。如何在oracle apex中使用表格形式的動態動作?

  • apex_application.g_f03:LOV(select name display, product_id return from products
  • apex_application.g_f04:文本字段 「價格」
  • apex_application.g_f05:文本字段 「量」。

我希望在選擇產品名稱(... f03)後在f04中查看該產品的價格。 SQL語句是這樣的:

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

如何使用動態操作或JavaScript函數做到這一點?

回答

1

好的,我會給你一個提示如何實現你的場景。你需要

事情,使其工作:

  • custom tabular爲 - 你已經擁有它
  • on demand process是去抓取產品的價格從DB
  • dynamic action聽,如果在f03值改變

按需過程

與下面的代碼

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; 

動力作用

你必須傾聽對jQuery選擇:input[name=f03]事件變化創建名爲getPrice需求的過程。用真實行動Execute JavaScript Code創建動態行爲。

在真實行爲中,您必須對on demand process執行ajax調用。示例代碼(工作)如下:

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); 
    } 
}); 

把東西放在一起,你會有答案你的問題。

Ps。 如果回答您的問題,請不要忘記標記爲有幫助。

相關問題