1

I have a javascript application where I'd like to add autocompletion to a form. Therefore, I render an array containing all available names in the controller so the array is available in the view (html).

$(function() {${"id"}.autocomplete({source: how to get the data here??}); });

Now I'd like read this data into a variable so I can use it in my javascript for the autocompletion... Can anyone tell me how to achieve this?

TIA

- astriffe

1 Answer 1

4

You need this data to be serialized in JSON, that when printed in javascript will be interpreted as javascript.

To help you with that, play! has Google JSON library

An example how could you achieve this is:

<% def gson = new com.google.gson.Gson(); %>
$(function() {${"id"}.autocomplete({source: ${gson.toJson(playVariable)} }); });

But this is ugly code, it would be better to use template extensions to achieve this

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.