문제

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