0

Create javascript from server

asked 2015-08-14 14:24:37 +0800

nazarenomartin83 gravatar image nazarenomartin83
1

updated 2015-08-14 17:31:17 +0800

Hello, i have a doubt, i'm using a library from the client to draw a chart in the HTML page. The chart is created from Javascript code. I need return from server dynamic javascript and i need know how i can this it do from ZKoss Framework. I attach the code: ... < ![CDATA[ for (var i = 0; i <= 30; i += 1) { d1.push([i,10]); d2.push([i, Math.pow(0.08*i, 3)]);
} ]] >
... I need push into "d1" and "d2" dynamic variables values from de server. Can anyone help me? Thanks! Hernan

delete flag offensive retag edit

5 Answers

Sort by ยป oldest newest most voted
0

answered 2015-08-14 15:07:20 +0800

cyiannoulis gravatar image cyiannoulis
1201 10

herman, please post again with some code

/costas

link publish delete flag offensive edit
0

answered 2015-08-17 02:24:13 +0800

MDuchemin gravatar image MDuchemin
2560 1 6
ZK Team

updated 2015-08-17 04:41:57 +0800

Hi Hernan,

As an additional information, if you are working in ZUML (.zul file), you can directly include JavaScript in you page, using the script component.

like this:

<script type="text/javascript" defer="true">
 <![CDATA[ 
    var d1 =[]; var d2 =[]; for(i=0; i<30;i++){
    d1.push([i,10]); d2.push([i, Math.pow(0.08*i,3)]); }
 ]]>
</script>

Edit: To call JS from the server side, you can use Clients.evalJavaScript() http://books.zkoss.org/wiki/ZKDeveloper'sReference/UIPatterns/UsefulJava_Utilities#evalJavaScript

Zk can let you transfer values from the server to the client in many ways, but the correct one on your situation depends on your design. Based on your sample, I understand that you are creating 2 arrays of 30 values, in the variable d1 & d2. How are you trying to use those variables?

Please post relevant server and client code.

link publish delete flag offensive edit
0

answered 2015-08-18 12:21:42 +0800

nazarenomartin83 gravatar image nazarenomartin83
1

The code: " ... < ![CDATA[ for (var i = 0; i <= 30; i += 0.1) { d1.push([i,10]); d2.push([i, Math.pow(0.08*i, 3)]);
} ]] > "

I need

link publish delete flag offensive edit
0

answered 2015-08-18 12:29:45 +0800

nazarenomartin83 gravatar image nazarenomartin83
1

Thanks! Yes, i need send those variables from server to client where both of them are arrays. How can i doing it? For example (from server):

Clients.evalJavaScript("test(1,2)");

How can i send some variables as arguments in the "evalJavaScript" method. Thanks again! Bye

link publish delete flag offensive edit
0

answered 2015-08-18 14:17:24 +0800

nazarenomartin83 gravatar image nazarenomartin83
1

I could resolve it on this way: ... ArrayList<string> s = new ArrayList<string>();
_s.add("1"); _s.add("5"); Clients.evalJavaScript("test("+
s+")");
... And the server call the function with the sent parameter. Thanks!

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2015-08-14 14:24:37 +0800

Seen: 31 times

Last updated: Aug 18 '15

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More