简体   繁体   English

Spring MVC AJAX @模型属性

[英]spring mvc ajax @ModelAttribute

In my Spring MVC application I have a data table, and I am using ajax and json to populate the data with pagination sorting etc. by the help of jquery.dataTables.js . 在我的Spring MVC应用程序中,我有一个数据表,并且我正在使用ajax和json通过jquery.dataTables.js进行分页排序等填充数据。 like this 像这样

$(document).ready(function() {
        $("#accordion").hide();

        $("#productList").dataTable({
            "bProcessing" : true,
            "iDisplayLength" : 10,
            "iDisplayStart" : 0,
             -------------
             --------------

            "sAjaxSource" :  ....'/product/productList',
            "aoColumns" : [ {
                "mData" : "year"
            }, {
                "mData" : "catg"
            }, {
                "mData" : "name"

Where on table I am displaying 4 columns. 我在桌上的哪儿显示4列。 Now On click on each row I want to show the details of selected record, around 50 fields. 现在,在单击每一行时,我要显示所选记录的详细信息,大约50个字段。

I can achieve by jquery , the time data table loading I can have get all the properties value to json and can set each id of 50 fields on click of each record. 我可以通过jquery来实现,加载时间数据表时,我可以将所有属性值都获取为json并且可以在单击每条记录时设置50个字段的每个id。

var table = $('#productList').DataTable();

$('#productList tbody').on('click', 'tr', function() {

    $("#accordion").show();

    var data = table.row(this).data();

    $('#type').val(data.type);
    $('#expdate').val(data.expDate);
    $('#place').val(data.place);
    $('#status').val(data.status);

But I want to use @ModelAttribute or model on click of a record It will do a ajax call set on ModelAttribute.so the deatils of record section will be inside form and each field have spring form path. 但是我想在单击记录时使用@ModelAttributemodel它会在ModelAttribute.set上进行ajax调用集,因此记录部分的详细信息将位于表单内部,并且每个字段都具有spring表单路径。

Is it possible?.please help on this. 有可能吗?请对此提供帮助。

You can modify this approach, because here they use hidden data. 您可以修改方法,因为这里它们使用隐藏数据。

All you need is replace row.child( format(row.data()) ).show(); 您只需要替换row.child( format(row.data()) ).show(); with something like that: row.child( format(fetchDataFromServer(row.data().id)) ).show(); 像这样的东西: row.child( format(fetchDataFromServer(row.data().id)) ).show();

DataTable changed their API, so it have to be changed according to old API doc or you can switch to use new version of library. DataTable更改了其API,因此必须根据旧的API文档进行更改,否则您可以切换为使用新版本的库。

UPD: Found a link to legacy API example. UPD:找到到旧版API示例的链接 Here you'll need to modify fnFormatDetails function invocation and pass data from server. 在这里,您需要修改fnFormatDetails函数调用并从服务器传递数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM