Need to pass an array in Java to javascript -


i using play framework 1.x.

is there way pass array controller template javascript array?

play automatically map parameters when post or javascript java. can use renderjson method pass object java javascript. use jquery map array. maybe if give context can little more.

    public static void getcontactstable() {     list<contacts> contacts = contacts.findallorderbyinserted();     renderjson(contacts); } 

this mapped route.

 $.getjson("@{viewcontacts.getcontactstable()}", function(data) {                           var series = {              data: []         };             $.each(data, function(index, item) {                         series.data.push([parseint(item.date), item.qty]);                         });           options.series.push(series);          var chart = new highcharts.chart(options);     });     

this small example of highcharts chart i've done.

here example of going other way , sending data rendered on page.

    public static void testing(list<long> selected) {      list<contacts> contacts = new arraylist<contacts>();      (long index : selected) {         contacts contact = contactservice.findbyid(index);         contacts.add(contact);     }     renderjson(contacts); } 

this takes javascript array. see mapping automatically map list fine. have java array though.

this javascript function.

       var template = 'selectedtemplate';  var selectedoutput = '#selectedoutput';         $.post('@{viewcontacts.testing()}',{ selected : selected }, function(data) {                     $(selectedoutput).html(tmpl(template, { items:data }));                   });      <div id="selectedoutput">         <script id="selectedtemplate" type="text/html">              <% (var = 0; < items.length; i++) {              var item = items[i];             %>              <li><%= item.name %> - <%= item.email %></li>             <% } %>            </script>     </div> 

as can see ajax request also. i'm taking selected data(which array of selected nodes) passing function. data (function(data)) , map items array. i'm using ejohn templating.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -