PUT_FUNCTION Procedure
Adds a function to an object.
The function is added without escaping, so ensure the content of the function is trusted. Do not use this method to add untrusted data, such as input from an end-user.
The function being added can either be a complete function, in which case it will be added as is, it can be a function body, in which case it will be wrapped with function(){}, or be an expression, which case it will be wrapped, and the expression returned.
Syntax
MEMBER PROCEDURE put_function (
p_key IN VARCHAR2,
p_code IN VARCHAR2,
p_type IN PLS_INTEGER,
p_omit_null IN BOOLEAN DEFAULT TRUE );Parameters
| Parameter | Description |
|---|---|
p_key |
The key. |
p_code |
The JavaScript code. |
p_type |
The type of code being added, use one of the constants:
|
p_omit_null |
Whether to omit the key value pair if the value is null. |
Example
Create an object with various properties.
declare
l_obj apex_t_javascript_object := apex_t_javascript_object();
begin
l_obj.open_object;
l_obj.put_function (
p_key => 'func1',
p_code => 'function(){return 42;}',
p_type => apex_javascript.c_type_function );
l_obj.put_function (
p_key => 'func2',
p_code => 'return 42;',
p_type => apex_javascript.c_type_function_body );
l_obj.put_function (
p_key => 'func3',
p_code => '42',
p_type => apex_javascript.c_type_expression );
l_obj.close_object;
sys.dbms_output.put_line( l_obj.to_clob );
end;
Output:
{"func1":function(){return 42;},"func2":function(){return 42;},"func3":function(){return 42;}}
Parent topic: APEX_T_JAVASCRIPT_OBJECT