How to set dynamic data when writing Javascript code through EncapsulateJS function

"$(function(){
    $.treeDropDown({
        el: '#"+EncodeJavaScript(WidgetId)+"',
        data: null,
        img: 'fa-folder-o',
        nodeClick: function(result) {
          console.log(result);
        }
      });
    });"

Hi all,

As above,this is a Javascript code that defined in the text input variable,It will be wrote in script tag of HTML by EncapsulateJS() function,Before this, I need to give a dynamic value to data,it just like el and WidgetId.However,dynamic variable of data are from database,the type mismatch

Hi Yi,

Is your post complete? The last sentence seems to be incomplete.

Also for a proper answer it is relevant if you are working on a Traditional or Reactive/Mobile application.

Regards,

Daniel

Daniël Kuhlmann wrote:

Hi Yi,

Is your post complete? The last sentence seems to be incomplete.

Also for a proper answer it is relevant if you are working on a Traditional or Reactive/Mobile application.

Regards,

Daniel

my last sentence means if I define an input variable to receive my data,the type is List,and it should also be spliced in Javascript code like WidgetId,but the code of type is text

It's Traditional application

Thanks Daniel


Hi,

I have no knowledge of the EncapsulateJS() function.

But the following is how I would pass parameters into a javascript function in Traditional Web app:


Say you have a javascript function on your screen or web-block defined:

function test(value1, value2) {
    alert('value1: ' + value1 + ', value2: ' + value2);
}

if you run the javascript from extended properties:

the values are passed.

My examples has hardcoded values, but you can of course use screen parameters too.

Regards,

Daniel


Daniël Kuhlmann wrote:

Hi,

I have no knowledge of the EncapsulateJS() function.

But the following is how I would pass parameters into a javascript function in Traditional Web app:


Say you have a javascript function on your screen or web-block defined:

function test(value1, value2) {
    alert('value1: ' + value1 + ', value2: ' + value2);
}

if you run the javascript from extended properties:

the values are passed.

My examples has hardcoded values, but you can of course use screen parameters too.

Regards,

Daniel


Only character constants or character variables can be passed in the test function,If we need to pass in complex data,how to do? This is also my trouble

Or we can do this: If I need to pass in an array of objects, it can be written like this: 

test('[{Id:0,Name:'v1'},[{Id:1,Name:'v2'}]')

Now the question becomes how to transform the data into this form in outsystems

Hi again,

Supposed in my example i have two input widgets bind to local parameters Var1 and Var2 then I can pass them as follows. 

"test('" + EncodeJavaScript(Var1) + "','" + EncodeJavaScript(Var2)+ "');"

Make sure the widget that calls the extended property action has the correct values by means of Ajax Refresh.

Regards,

Daniel

Daniël Kuhlmann wrote:

Hi again,

Supposed in my example i have two input widgets bind to local parameters Var1 and Var2 then I can pass them as follows. 

"test('" + EncodeJavaScript(Var1) + "','" + EncodeJavaScript(Var2)+ "');"

Make sure the widget that calls the extended property action has the correct values by means of Ajax Refresh.

Regards,

Daniel


EncodeJavaScript input data type is text, but the data type  that I want to pass in function is List

Solution

You will have to serialize the list into a JSON string using OutSystems.

And then in Javascript use JSON.parse to deserialize it again.

Solution

Daniël Kuhlmann wrote:

You will have to serialize the list into a JSON string using OutSystems.

And then in Javascript use JSON.parse to deserialize it again.

It'ok, I am most grateful for your support!


Your welcome!