次のように、 POJOをJSONオブジェクトとして返すJava (Spring MVC)バックエンドがあります。
@RequestMapping(value = "/getWidgetsByType", method = RequestMethod.POST)
public @ResponseBody List<WidgetVO> getWidgetsByType(@RequestParam("type") String type)
{
return widgetDAO.getWidgetsByType(token);
}
public class WidgetVO {
private String type;
private String name;
private boolean isAwesome;
// Getters and setters, etc.
}
フロントエンドでは、 jQuery/getWidgetsByType
呼び出しの内部から呼び出して、そこから返されるJSONの結果を使用してデータテーブルにデータを入力しようとしています。具体的には、次のように、ページの読み込み時に現在空のタグ内にデータテーブルを表示する必要があります。 $.getJSON
<div>
<div id="#table-to-display"></div>
var t = getTypeFromDOM();
$.getJSON(
url: "/getWidgetsByType",
data: {
type: t
},
success: function() {
// How do I extract the JSON version of the List<WidgetVO>'s coming
// back from the server and use them to populate the table?
$("#table-to-display").datatable();
}
);
(type、name、isAwesome)のフィールドとdatatable
同じ列を、すべて値(レンダラーなどなし) として含めたいと思います。WidgetVO
String
ここで助けてくれてありがとう!