2015-11-30 29 views
0

這是我正在嘗試的示例代碼。如何將日誌添加到jqgrid列中?

{ 
     name : 'scopeName', 
     index : 'scopeName', 
     width: '400px', 
     resizable : true, 
     align : "left", 
     editable : true, 
     edittype : "select", 
     editoptions : { 
      value : getSequenceNumbers() 
     }, 
     editrules : { 
      required : true 
     } 

function: 

    function getSequenceNumbers() { 
     alert("here123"); 
     $.getJSON("http://localhost:8039/ReleaseManagementApp/releasemgmt/config/Q2FY16/scope", null, function(data) { 
     if (data != null) { 
      alert("here"); 
      //construct string. 
      //(or the server could return a string directly) 
      for (var i=0; i<data.length; i++) { 
       sel.append('<option value="' + data[i].scopeName + '">' + data[i].scopeName + '</option>'); 
      } 
     } 
    }); 
} 

這裏是來自server-link的json數據。

data: 
[ 
    { 
    "scopeId": 101, 
    "scopeName": "FCM Attributes to be captured in CG1 OM", 
    "scopeDesc": "New Attributes to be captured in FCM", 
    "scopeIdentifier": "Q2FY16_FCM_Attributes_to_be_ca" 
    }, 
    { 
    "scopeId": 104, 
    "scopeName": "PBI000000043281", 
    "scopeDesc": "OMLSS-OM-Production Bug- Workflow-Line Workflow purged even before Line is closed", 
    "scopeIdentifier": "FY16_OCT_MR_PBI000000043281" 
    }, 
    { 
    "scopeId": 106, 
    "scopeName": "PBI000000049219", 
    "scopeDesc": "AS-T Inbound and re-process program issues", 
    "scopeIdentifier": "FY16_OCT_MR_PBI000000049219" 
    } 
] 

我想知道如果我可以從上面的響應填充scopeName成的jqGrid作爲選擇標籤。

回答

0

相反,我建議你使用自定義格式此:

function getSequenceNumbers() { 
     alert("here123"); 
     var sel = '<select>'; 
      sel +='<option value="select">Select...</option>'; 
     $.getJSON("url", null, function(data) { 
     if (data != null) { 
      alert("here"); 
      //construct string. 
      //(or the server could return a string directly) 
      for (var i=0; i<data.length; i++) { 
       sel += '<option value="' + data[i].scopeName + '">' 
         + data[i].scopeName + '</option>'; 
      } 
      sel +="</select>"; 
     } 
    }); 
    return sel; 
} 

{ 
    name : 'scopeName', 
    index : 'scopeName', 
    width: '400px', 
    resizable : true, 
    align : "left", 
    formatter:getSequenceNumbers // <----use the function here 
} 

現在你可以從這個函數返回一個select元素