如何在数据表编辑器中动态传递选择框值


How to pass the select box value as dynamically in datatable editor?

>我正在尝试传递数据表编辑器部分的动态值,如果我们单击数据表中的编辑按钮,则必须选择它。这是我的代码:

var editor; // use a global for the submit and return data rendering in the examples
$(document).ready(function() {
    editor = new $.fn.dataTable.Editor({
        ajax: 'staff-array.php',
        table: '#example',
        fields: [{
            label: 'Project ID:',
            name: 0
        }, {
            label: 'Description:',
            name: 1
        }, {
            label: 'Notes:',
            name: 2
        },
        {
            label: 'Status:',
            name: 3,
            type:  "select",
            "ipOpts": getStateList()
        }]
    });

这是用于获取选择框值的函数:

function getStateList() {
    var aStateList = new Array();
    $.ajax({
        url: 'server_processing.php',
        type: 'POST',
        dataType: 'json'
    }).done(function(json){
        for (var a = 0; a < json.length; a++) {
            aStateList[a] = { "label": json[a][0], "value" : json[a][1] };
        }
        return aStateList;
    });
}
嗨,

我已经完成了以下更改,然后它工作正常,

var test= new Array({"label" : "a", "value" : "a"});
function getStateList(){
test.splice(0,1);
$.ajax({
  url: 'server_processing.php',
  async: false,
  dataType: 'json',
  success: function (json) {
      for(var a=0;a<json.length;a++){
        obj= { "label" : json[a][1], "value" : json[a][0]};
        test.push(obj);
      }
    }
});
return test;
}