[英]is this the right way to use if statement?
is this the right way to use if statement ? 这是使用if语句的正确方法吗? or i can't use if statement inside this script ? 还是我不能在脚本中使用if语句?
<script type="text/javascript" charset="utf-8">
$(document).ready(function () {
$('#customerTable').dataTable({
"bServerSide": true,
"sAjaxSource": "Customer/AjaxHandler",
"bProcessing": true,
"aoColumns": [{
"sName": "CustomerId",
"bVisible": false
}, {
"sName": "NamaPerusahaan",
"bSearchable": true,
"bSortable": true,
"fnRender": function (oObj) {
return '<a href="/Customer/Details/' +
oObj.aData[0] + '">' + oObj.aData[1] + '</a>';
}
}, {
"sName": "Alamat1"
}, {
"sName": "Telephone"
},
//below is the datetime
{
"sName": "NonActiveDate",
"bSearchable": true,
"bSortable": true,
"fnRender": function (oObj) {
if(oObj.aData[4] <= @DateTime.Now) {
return '<span style="color:green">' + oObj.aData[4] + ' </span>';
} else {
return '<span style="color:red">' + oObj.aData[4] + ' </span>';
}
}
}, {
"sName": "Edit",
"bSearchable": false,
"bSortable": false,
"fnRender": function (oObj) {
return '<a href="/Customer/Edit/' + oObj.aData[0] + '" class="btn mini blue"><i class="icon-edit"></i>Edit</a>';
}
}, {
"sName": "Delete",
"bSearchable": false,
"bSortable": false,
"fnRender": function (oObj) {
return '<a href="/Customer/Edit/' + oObj.aData[0] + '" class="btn mini red"><i class="icon-trash"></i>Delete</a>';
}
}
]
});
});
</script>
with this code my TglNonAktif font color become all green,i think i have the problem with the if statement :D need help from anyone ..... 用此代码,我的TglNonAktif字体颜色变为全绿色,我认为我对if语句有疑问:D需要任何人的帮助......
Q: "is this the right way to use if statement?" 问: “这是使用if语句的正确方法吗?”
A: No, not really :) 答:不,不是真的:)
Having Razor injection into lengthy JavaScript means you cannot place your JavaScript into a separate file (so no bundling or caching). 将Razor注入冗长的JavaScript中意味着您无法将JavaScript放入单独的文件中(因此,请勿进行捆绑或缓存)。
Your question raises too many other questions, but if your aim is to inject a client-side variable from the server, you are better off injecting into a single "global" variable (global in JS is window
) like this: 您的问题提出了许多其他问题,但是如果您的目标是从服务器注入客户端变量,则最好将其注入单个“全局”变量(JS中的global是window
),如下所示:
<script type="text/javascript">
window.loadDate = @(DateTime.Now.ToString('appropriateformattinghere'));
</script>
that can be referenced from any javascript file as 可以从任何javascript文件中引用为
if(oObj.aData[4] <= window.loadDate)
The code above assume a number will be generated (which a date hopefully will be). 上面的代码假定将生成一个数字(希望是一个日期)。
The key here is "what is the format of oObj.aData[4]
"? 关键是“ oObj.aData[4]
的格式是什么?”? Is it a JavaScript Date
object? 它是JavaScript Date
对象吗? Is it milliseconds since Stephen Hawkings was born? 斯蒂芬·霍金斯出生后是毫秒吗? please be specific (and/or provide an example). 请具体说明(和/或提供示例)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.