1

I have an javaScript function in my Thymeleaf page which has an array of countries

  var countries = ["Australia","Italy","France","Spain","India","China"];

But I want to pass that list of Countries from the controller method. So I passed an List of strings to the view via the model and accessed it in javaScript as follows,

Controller:

 List<String> list=new ArrayList<String>();
    list.add("Australia");
    list.add("Italy");
    list.add("France");
    list.add("Spain");
    list.add("India");
    list.add("China");

    model.addAttribute("list",list);

javaScript:

 var countries=[[${list}]];

But It doesn't work as expected.So please suggest a way to do this successfully

3

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.