0

I've passed a map of [String, List[String]] to one of my views in Play. The user is selecting a value from a dropdown. This value is a key in my map. I am using this key to then populate a second dropdown using the value in the map - a list of String. However, I do not know how to use Play's template language to get the value out of my map since I'm retrieving the key via JavaScript.

This is my code:

function selectSubCat() {
        var key = $("#monthYear").find(":selected").text(); // get the selected option's text. This is the map key.

// Here lies the issue. mailingRunDates is the name of the map I've passed to the view. Play says: val key not found.
        var runDatesList = @mailingRunDates(key) 

1 Answer 1

1

I think you are trying to communicate javascript with the playframework template engine. And I am afraid you can't do it except if you are trying to communicate with a controller using ajax.

In your case the compiler is looking for a variable declared as a dynamic statement. It is code that is run in the server, so when the template is transformed into html it cannot be changed. You can declare a variable in the template system using something like @{key=12}.

So in this case, I would extract all the Map[String, List[String]] to a javascript object to create that functionality in javascript.

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.