0

我有以下 ColModel 定义的 jqGrid

colModel: [
        .
        .
        .
        {
            name: 'ReadingTransferTime', index: 'ReadingTransferTime', width: 78, formatter: 'date', formatoptions: { srcformat: 'm/d/Y', newformat: 'm/d/Y' },
            sorttype: 'date', fixed: true, align: 'center'
        },
        .
        .
        .
        {
            name: 'CPAPStatus', index: 'CPAPStatus', sortable: false, align: 'center', formatter: LoadCPAPFollowUpDialog, width: 100, fixed: true,
            cellattr: function (rowId, tv, rawObject, cm, rdata) { return 'style="white-space: normal!important;' }
        },            
        { name: 'CPAPDeliveryReason', hidden: true },
        { name: 'CPAPDeliveredDate', hidden: true },
        { name: 'CPAPDeliveryStatus', hidden: true }
        ],

自定义格式化程序LoadCPPFollowUpDialog如下

function LoadCPAPFollowUpDialog(cellvalue, options, rowObject) {        
var paramList = JSON.stringify({
    ReadingID: rowObject.ReadingID,
    TransferTime:rowObject.ReadingTransferTime,
    PatientName: rowObject.PatientFullName,
    PAPDeliveredDate: rowObject.CPAPDeliveredDate,
    NonDeliveryReason: rowObject.CPAPDeliveryReason,
    GridID: "HSTCandidatesDtls"
});

return "<img src='../Content/images/icons/edit.gif' title='" + "@VirtuOxAdmin.SleepStudyDetails_Image_CPAPStatus" + "' \
onClick='openDialog(\"SleepStudyDtlsDialog\",\"" + "@VirtuOxAdmin.SleepStudyDetails_Dialog_CPAPStatus" + "\",\"CPAPDelivery\"," + paramList + ",\"500\",\"auto\")'>" + "<span>" + rowObject.CPAPDeliveryStatus + "</span>";

}

在此列值 ReadingTransferTime 和 CPAPDeliveredDate 的格式化程序中,我得到的字符串值类似于 /Date(1380565800000)/ 而不是 datetime 对象。这给我的操作方法CPAPDelivery接受错误的参数值造成了问题。如何解决这个问题?

我从这里采取了 1 个解决方案 并将我的 paramList json 对象形成为

var paramList = JSON.stringify({
    ReadingID: rowObject.ReadingID,
    TransferTime:new Date(rowObject.ReadingTransferTime.match(/\d+/)[0]*1),
    PatientName: rowObject.PatientFullName,
    PAPDeliveredDate: (rowObject.CPAPDeliveredDate!=null? new Date(rowObject.CPAPDeliveredDate.match(/\d+/)[0]*1):null),
    NonDeliveryReason: rowObject.CPAPDeliveryReason,
    GridID: "HSTCandidatesDtls"
});

这是解决上述问题的正确方法吗?或者 jqGrid 有一些内置的功能来处理它。

4

1 回答 1

0

试试这个,

 string jsonDate = "/Date(1380565800000)/";
 jsonDate = jsonDate.Replace("/Date(", string.Empty); 
 jsonDate = jsonDate.Replace(")/", string.Empty);

 var date = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddMilliseconds(long.Parse(jsonDate));
 date = date.AddDays(1);

希望这可以帮助。

于 2013-10-10T09:40:35.000 回答