I have a function which popup a modal window:

function showTable(employees) {
    var result = $('#empl');
    result.empty();
    $.each(employees, function (index, employee) {
        var tr = $('<tr/>');
        tr.append($('<td/>').html(employee.id));
        tr.append($('<td/>').html(employee.name));
        result.append(tr);
    });
    $('#myModal').modal('show');
}

And code which invoke this function:

<button type="button" class="btn" onclick="showTable(${company.employees})">View</button>

My Company class

public class Company implements Serializable {
    private Integer id;
    private String name;
    private List<Employee> employees;

But function doesn't work. How to make it work?

有帮助吗?

解决方案

Well, you need to convert your list of employees to JSON and pass the JSON string to the JavaScript function.

In order to do that have a look at the various JSON libraries out there, e.g. Gson, Jackson, json-simple etc.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top