我需要找到一個更有效的方法來達到一個JavaScript對象,找到空值,並用空字符串(或其他內容)替換它們。這就是我的,它的功能,但我需要一個更有效的方法,我只知道必須有一個使用$ .each,但我似乎無法弄清楚。
這是什麼工作...我想用更優雅的東西來代替所有這些if語句?
var oMilestone = {
sTitle: $(this).attr("ows_Title"),
sStatus: $(this).attr("ows_Status"),
sOwner: $(this).attr("ows_Assigned_x0020_Owner"),
sStart: SPConvertDate($(this).attr("ows_Start_x0020_Date")),
sDue: SPConvertDate($(this).attr("ows_Due_x0020_Date")),
sPercent: $(this).attr("ows_Percent_x0020_Complete"),
sComments: $(this).attr("ows_Update_x0020_Comments")
}
if (oMilestone.sOwner == null) {
oMilestone.sOwner = " "
}
if (oMilestone.sStart == null) {
oMilestone.sStart = " "
}
if (oMilestone.sDue == null) {
oMilestone.sDue = " "
}
if (oMilestone.sPercent == null) {
oMilestone.sPercent = " "
}
if (oMilestone.sComments == null) {
oMilestone.sComments = " "
}
任何幫助?
凱文
這些值不能爲空,'.attr()'將返回字符串或'undefined' .. – 2013-02-26 21:38:34