我想根据当前月份显示对象 我的代码是
for (let m of this.monthEvent){
m=new Date();
if(m.getMonth() === new Date().getMonth()){
this.thisMonth=m;
}
return this.thisMonth;
我的数组是
[{title: "", date: "2018-03-29"},
{title: "", date: "2018-04-13"},
{title: "", date: "2018-04-12"},
{title: "leave", date: "2018-04-11"}
{title: "", date: "2018-04-16"}]
它显示m.getTime不是函数
我想显示当前月份事件
提前致谢
答案 0 :(得分:1)
filter
来获取特定事件。var [_, month] = e.date.split('-');
var array = [{ title: "a", date: "2018-03-29" }, { title: "b", date: "2018-04-13" }, { title: "c", date: "2018-04-12" }, { title: "leave", date: "2018-04-11" }, { title: "d", date: "2018-04-16" }],
currentMonth = new Date().getMonth() + 1,
events = array.filter(e => {
var [_, month] = e.date.split('-'); // Or, var month = e.date.split('-')[1];
return currentMonth === +month;
});
console.log(events);
.as-console-wrapper { max-height: 100% !important; top: 0; }