gpt4 book ai didi

javascript - jQuery - 填充对象中缺失的星期几值

转载 作者:行者123 更新时间:2023-12-02 14:56:02 24 4
gpt4 key购买 nike

我想显示注册用户在注册期间填写的营业时间:

这是“”,它以这种方式存储在数据库中:

[
{"day":"Maandag","daylabel":"Maandag","fromtime":"15:30","fromtimelabel":"3:30 pm","totime":"22:00","totimelabel":"10:00 pm"},
{"day":"Dinsdag","daylabel":"Dinsdag","fromtime":"15:30","fromtimelabel":"3:30 pm","totime":"22:00","totimelabel":"10:00 pm"},
{"day":"Donderdag","daylabel":"Donderdag","fromtime":"15:30","fromtimelabel":"3:30 pm","totime":"22:00","totimelabel":"10:00 pm"},
{"day":"Vrijdag","daylabel":"Vrijdag","fromtime":"15:30","fromtimelabel":"3:30 pm","totime":"22:00","totimelabel":"10:00 pm"},
{"day":"Zaterdag","daylabel":"Zaterdag","fromtime":"09:30","fromtimelabel":"9:30 am","totime":"+00:00","totimelabel":"12:00 am (next day)"},
{"day":"Zondag","daylabel":"Zondag","fromtime":"09:30","fromtimelabel":"9:30 am","totime":"+00:00","totimelabel":"12:00 am (next day)"}
]

这是我解析的函数:

config.profile.core.parseAvailability = function(value){
if(value){
try {
var availabilityDays = JSON.parse(value);
$jq.each(availabilityDays, function(index, day) {
$jq('#availability').append('<div class="col-sm-5">'+day['daylabel']+'</div><div class="col-sm-7">'+day['fromtime']+' - '+day['totime']+'</div>');
});
} catch (error) {
console.error(error);
}
}
};

这就是它在页面上的显示方式:

enter image description here

问题:

正如您可能看到的,周三(在“dinsdag”和“donderdag”之间的荷兰语“woensdag”)缺失,因为它没有故意填写(可能会被关闭)在特定的一天)。因为那天没有存储,所以我无法显示它。

如何用空值显示缺失的日期?

最佳答案

不要循环遍历您获得的数据,而是循环遍历您想要的数据,然后显示与之匹配的数据

var days = ['Maandag', 'Dinsdag', 'Woensdag', 'Donderdag', 'Vrijdag', 'Zaterdag', 'Zondag'];
var availabilityDays = JSON.parse(value);

for (var day of days) {
var details = availabilityDays.find(function (detail) {
return detail.day == day;
});

var detailsText = '';

if (details) {
detailsText = details['fromtime']+' - '+details['totime']
}

$jq('#availability').append('<div class="col-sm-5">'+day+'</div><div class="col-sm-7">' + detailsText + '</div>');
}

关于javascript - jQuery - 填充对象中缺失的星期几值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35797207/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com