如何從Controller的Action方法返回的JSON對象填充jQuery數據表列?

[英]How to populate a jQuery datatable column from a JSON object returned by a Controller's Action method?


I am using jQuery datatable plugin and one of the columns is a select box. It renders fine if I assign some static values such as True/False as below.

我正在使用jQuery datatable插件,其中一列是一個選擇框。如果我分配一些靜態值,如下面的True / False,它會呈現正常。

"aoColumns": [{}, {}, {}, {},
        {
            type: 'select',
            onblur: 'submit',
            data: "{'True':'True', 'False':'False'}"
        }]

But I need to get the values of select box from a JSON object that is returned from a controller's action method. Here is my action method. Any ideas on how to get the data populated into the select box? Thanks for any help.

但是我需要從控制器的action方法返回的JSON對象中獲取select框的值。這是我的行動方法。有關如何將數據填入選擇框的任何想法?謝謝你的幫助。

public ActionResult GetAllFields(int connId)
    {
        Conn conn = GetConn(connId);
        List<string> fields = conn.GetAllFields();

        return Json(new Result()
        {
            Result = Action.Successful,
            Data = fields                    
        }, JsonRequestBehavior.AllowGet);
    }

1 个解决方案

#1


1  

I would use mRender to display the result of a function that loads/populates the content of your dropdown.

我會使用mRender來顯示加載/填充下拉列表內容的函數的結果。

Example from datatables.net:

datatables.net的示例:

// Use as a function to create a link from the data source
$(document).ready( function() {
  var oTable = $('#example').dataTable( {
    "aoColumnDefs": [ {
      "aTargets": [ 0 ],
      "mData": "download_link",
      "mRender": function ( data, type, full ) {
        return '<a href="'+data+'">Download</a>';
      }
    } ]
  } );
} );

Depending on the content of your dropdown, you may also want to consider the solution user403295 posted to this question.

根據下拉列表的內容,您可能還需要考慮發布到此問題的解決方案user403295。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/12/28/7300720179ec7205ba52ab204ac5b688.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com