简体   繁体   English

在FTL中将JavaScript变量发送到我的模型

[英]Send a javascript var to my model in FTL

I have a list of checkboxes, with this function i get my array of checked items: 我有一个复选框列表,使用此功能,我可以得到检查项目的数组:

 var selected = new Array(); 
 $('#bloqCountries input:checked').each(function() { selected.push($(this).val()); });

I have a model class and i need to send by parameter this array making something like this: 我有一个模型类,我需要通过参数发送此数组,使之类似于:

 [#assign searchResults =model.searchContent(selected) /]

But Javascript is in client side and Freemarker in server side... 但是Javascript在客户端,而Freemarker在服务器端...

Then i don´t know how to get this array in my model to call my modelClass.. 然后我不知道如何在我的模型中获取此数组以调用我的modelClass。

My idea is making by the request, transforming the array in string and making a split() method in java to delete the "-" between the words 我的想法是通过请求,将字符串转换为字符串,并在Java中创建split()方法以删除单词之间的“-”

I don't know how to send this content because i´m not using ajax and I don't think its necessary. 我不知道如何发送此内容,因为我没有使用Ajax,我也不认为这是必需的。

Simply put, you can't do that. 简而言之,你不能那样做。 FTL template is executed on the server and only once, to produce HTML and to send it to browser. FTL模板仅在服务器上执行一次,以生成HTML并将其发送到浏览器。 JS is executed only when browser receives and processes said HTML. 仅当浏览器接收并处理所述HTML时,才执行JS。 By that time, FTL process is long dead. 到那时,FTL进程早已一dead不振。

If you want to communicate with the server, ajax is the only way to do that. 如果要与服务器通信,则ajax是唯一的方法。 You might find some inspiration and examples of using ajax w/ Magnolia at here or here . 这里这里,您可能会发现一些启发和使用ajax w / Magnolia的示例。

HTH, HTH,
Jan 一月

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM