Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top