编辑: 我在过滤器中发现了问题的一部分,如果我打印console.log(day),则当我在12月到达时,其日期等于01/00/2019,02/00/2019 ...因为.get('month ')从索引0开始,尽管我不知道如何解决它
当我检索服务器的不可用日期(一个有20多个日期的大表)时,我设法禁用了第一个日期范围,但不是全部日期。
这是我的服务器示例的响应:
{
"arrayOfUnavailableDates": [
"2018-12-01",
"2018-12-02",
"2018-12-03",
"2018-12-04",
"2018-12-05",
"2018-12-06",
"2018-12-07",
"2018-12-08",
"2018-12-09",
"2018-12-10",
"2018-12-11",
"2018-12-12",
"2018-12-13",
"2018-12-14",
"2018-12-15",
"2018-12-16",
"2018-10-05",
"2018-10-06",
"2018-10-07",
"2018-10-08",
"2018-10-09",
"2018-10-10"
]
}
我得到与这个数组成角度的
getUnavailableDatesOfCoach(coachId: number): Observable<Date[]> {
const queryParams = `?coachId=${coachId}`;
return this._http
.get<{ arrayOfUnavailableDates: Date[] }>(
`${this.apiUrlUnavailableDate}` + queryParams
)
.pipe(map(data => data.arrayOfUnavailableDates));
}
这是我的过滤方法:
myFilter = (d: Date): boolean => {
this._route.queryParams.subscribe(params => {
if (params['coachId']) {
this._unavailableDateService
.getUnavailableDatesOfCoach(params['coachId'])
.subscribe(arrayOfUnavailableDates => {
this.disableDateList = arrayOfUnavailableDates;
console.log(this.disableDateList);
});
}
});
const dateMoment = moment(d);
let date: any;
let month: any;
// console.log(dateMoment.get('date'));
if (dateMoment.get('date').toString().length < 2) {
date = '0' + dateMoment.get('date').toString();
} else {
date = dateMoment.get('date').toString();
}
if (
dateMoment
.add(1, 'M')
.get('month')
.toString().length < 2
) {
month =
'0' +
dateMoment
.get('month')
.toString()
.toString();
} else {
month = dateMoment
.get('month')
.toString()
.toString();
}
const day = dateMoment.get('year').toString() + '-' + month + '-' + date;
// console.log(day);
return !this.disableDateList.includes(day);
// tslint:disable-next-line:semicolon
};
日期选择器取消激活10月5日至10日的日期,但不禁用12月的日期...
谢谢!
答案 0 :(得分:1)
尝试这样:
from pyspark.sql.functions import struct
new_df = df.select('id', struct('dogs', 'cats').alias('animals'))
new_df.show(2, False)
#+---+-------+
#|id |animals|
#+---+-------+
#|1 |[2, 0] |
#|2 |[0, 1] |
#+---+-------+
new_df.printSchema()
#root
# |-- id: long (nullable = true)
# |-- animals: struct (nullable = false)
# | |-- dogs: long (nullable = true)
# | |-- cats: long (nullable = true)