title: How do I pass a playframework template list item variable as input to a javascript function?
body: <p>Sorry if this is trivial or having been asked before using a different terminology. Im relatively new to web programming and specially to play framework.</p>
  
  <p>My scala web template looks like: </p>
  
  <pre><code>@(alarms: List[Alarm], alarmForm: Form[Alarm]) 
  
  @import helper._
  
  @main("Alarm list") { 
      &lt;script id="showInfoScript" language="javascript" type="text/javascript"&gt;
     function showInfoFromAlarm(alarm) {
         $("#patientName").text(alarm.Patient.name);
      };
      &lt;/script&gt;
  
  
      &lt;header&gt;
          &lt;h1&gt; EMHT &lt;/h1&gt;
      &lt;/header&gt;
  
   &lt;div class="collumnsContainer"&gt;    
      &lt;div&gt; &lt;section class="alarmListSection"&gt;
          &lt;h2&gt;@alarms.size() alarm(s)&lt;/h2&gt;
  
          &lt;div class="list-group"&gt;
          @for(alarm &lt;- alarms){
            &lt;a href="#" onclick="showInfoScript(@alarm);return false;" class="list-group-item active"&gt;
              &lt;h4 class="list-group-item-heading"&gt;@{alarm.id} of type @{alarm.`type`} &lt;/h4&gt;
              &lt;p class="list-group-item-text"&gt;Callee @{alarm.callee.phoneNumber} ;Patient @{alarm.patient.personalNumber} &lt;/p&gt;
            &lt;/a&gt;
           }  
          &lt;/div&gt;
  
      &lt;/section&gt;&lt;/div&gt; 
  </code></pre>
  
  <p>where I basically try to have each button created in the <code>@for(alarm &lt;- alarms)</code> to call the javascript function <code>showInfoScript</code> with the alarm object instance corresponding to that button.</p>
  
  <p>As it is the code fails. I understand that the problem is that the object in the for loop is a scala object and it need some sort of conversion to be passed to the javascript function. </p>
  
  <p>But what would be the simplest way to convert it to something understandable by the javascript? I thought of json and I've read about doing a <code>@Json.toJson(alarm)</code>, but I got an error that there were no serializer and that Id need to "implement an implicit Writes or Format for this type".</p>