2014-11-21 23 views
1

我想通過數據表編輯器部分的動態值,它必須選擇,如果我們點擊數據表中的編輯按鈕。這裏是我的代碼:如何在數據表編輯器中動態地傳遞選擇框的值?

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; 
    }); 
} 

回答

0

您好我已經做了以下變化那麼它的做工精細,

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; 
} 
相關問題