isAdmin的值=假
的代碼不會進入條件
if(!isAdmin)
結果,我沒有得到期望的輸出。 這就是下面好象叫在asp.net:
<span onclick="DisplayPrdWeightGrd('<%#Container.ItemIndex + 1 %>','<%# Eval("OrderId")%>','<%= Convert.ToBoolean(Utility.IsAdmin()) %>');">
function DisplayPrdWeightGrd(index, OrderId, isAdmin) {
$.ajax({
type: "POST",
url: "../handlers/DisplayOrderDetail.ashx?OrderId=" + Orderid + "&tk=" + $.now(),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
if ($('#tableOrderDetail_' + index + ' tr').length <= 1) {
$.each(data, function(i, v) {
setDataOnRow(index, v, i);
});
}
},
failure: function(response) {
alert("fail");
},
error: function(response) {
alert(response);
}
});
function setDataOnRow(idx, v, i) {
var totalprice;
if (v.IsGST == true) {
totalprice = parseFloat(v.TotalPrice * (1.1)).toFixed(2);
} else {
totalprice = parseFloat(v.TotalPrice).toFixed(2);
}
//debugger;
var obj = $('#tableOrderDetail_' + idx + ' tr td table:last');
if (!isAdmin) {
$('#tableOrderDetail_' + idx + ' tr:last').after('<tr>' +
'<td width="25%" >' + (i + 1) + '</td>' +
'<td width="25%" class="center">' + v.ProductName + '</td>' +
'<td width="12%" class="center">' + v.NoOfCarton + '</td>' +
'<td width="12%" class="center">' + v.ProductQuantity + '</td>' +
'<td width="12%" class="center">' + v.OriginalPrice + '</td>' +
'<td width="12%" class="center">' + v.OrderPrice + '</td>' +
'<td width="10%" class="center">' + v.IsGST + '</td>' +
'<td width="10%" class="center">' + v.Discount + '</td>' +
'<td width="12%" class="center">' + totalprice + '</td></tr>');
} else {
$('#tableOrderDetail_' + idx + ' tr:last').after('<tr>' +
'<td width="25%" >' + (i + 1) + '</td>' +
'<td width="25%" class="right">' + v.ProductName + '</td>' +
'<td width="12%" class="right">' + v.NoOfCarton + '</td>' +
'<td width="12%" class="right">' + v.ProductQuantity + '</td>' +
'<td width="12%" class="right">' + v.OriginalPrice + '</td>' +
'<td width="12%" class="right">' + v.OrderPrice + '</td>' +
'<td width="10%" class="right">' + v.IsGST + '</td>' +
'<td width="10%" class="center">' + v.Discount + '</td>' +
'<td width="12%" class="center">' + totalprice + '</td></tr>');
}
}
我試着調試器,它總是將是價值isAdmin else條件是真還是假。卡在這裏。
如果我更改爲if(isAdmin),那麼它在條件而不是其他。反應是副詩 –
檢查typeof isAdmin。如果是字符串,那麼它總是會進入if條件。 – Sachin
確定它的類型是字符串 –