質問

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