gpt4 book ai didi

javascript - 如何使用 Angular 8 为对象数组提供不同的日期

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

我在 angular8 应用程序中使用了 bootstarp 4 datetimepicker。在这里,我获取了所有 3 个字段中的最新日期,但我必须获取给该特定字段的日期。我已经使用了 ngModel,这个问题是基于此吗?

DEMO

TS:

dateRestriction(event, restriction) {
$(".onlyDateTime").datetimepicker();
$(".onlyDate").datetimepicker({ format: "L" });
$(".onlyDateTime")
.datetimepicker()
.on("dp.change", e => {
const date = e.date;
console.log(e.date.format("L"));
this.Restrictions[restriction].datetime = e.date.format("L");
});
}

HTML:

<div class="col-6 {{isReadOnly ? 'link-disabled' : ''}}"
*ngFor="let restrictValue of Restrictions;let i = index">
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="{{restrictValue.id}}"
[checked]="restrictValue.boolValue" (change)="restrictValue.boolValue = $event.target.checked"
>
<label class="custom-control-label" for="{{restrictValue.id}}">{{restrictValue.label}}</label>
</div>
<div class="form-group">
<input type="text" class="form-control onlyDateTime" placeholder="MM/DD/YYYY HH:MM AM/PM"
[disabled]="!restrictValue.boolValue" [(ngModel)]="restrictValue.datetime" (change)="dateRestriction($event,restrictValue)" (click)="dateRestriction($event, i)"
[ngModelOptions]="{standalone: true}" >
</div>
</div>

最佳答案

自从您使用 Jquery 日期选择器更改日期时间选择器事件以来。它在日期选择器的点击事件之前被调用。

试试这个

ngAfterViewInit() {
$(".onlyDate").datetimepicker({ format: "L" });
let dat = null;
$(".onlyDate")
.datetimepicker()
.on("dp.hide", e => {
const date = e.date;
let dat = e.date.format("L");
this.Restrictions[this.selectedIndex].datetime = dat;
});
}

dateRestriction( i) {
this.selectedIndex = i;
}

Forked Example

关于javascript - 如何使用 Angular 8 为对象数组提供不同的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60276987/

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