【发布时间】:2015-02-18 23:16:48
【问题描述】:
我在我的项目中使用 Knockout 和 Typescript,我需要在视图模型中构建三个具有 datetime 类型的字段。满足条件时需要更新这些内容。
我有什么:
查看:
<div data-bind="if: step1CompleteY">
<span data-bind="text: step1CompleteY" />
<input type="datetime" data-bind="value: timestampSt1()" />
</div>
<div data-bind="if: step12Complete">
<span data-bind="text: step12Complete" />
<input type="datetime" data-bind="value: timestampSt2()" />
</div>
<div data-bind="if: step23Complete">
<span data-bind="text: step23Complete" />
<input type="datetime" data-bind="value: timestampSt3()" />
</div>
查看模型:
myTimestamp = ko.observable(new Date().getDate() + "/" + new Date().getMonth() + "/" + new Date().getFullYear() + " " + new Date().getHours() + ":" + new Date().getMinutes());
timestampSt1 = ko.observable(this.myTimestamp);
timestampSt2 = ko.observable(this.myTimestamp);
timestampSt3 = ko.observable(this.myTimestamp);
step1CompleteY = ko.computed({
read: () => this.objectChecks.exportValue() === 'Yes'
})
step12Complete = ko.computed({
read: () => { return this.objectChecks.exportValue() === 'No' || this.objectChecks.rfqStatusValue() === 'Approved' }
})
step23Complete = ko.computed({
read: () => { return (this.objectChecks.indemnityValue() === 'Yes' || this.objectChecks.indemnityValue() === 'N/A' || this.objectChecks.rfqStatusValue() === "Denied") }
})
这里的问题是,日期时间出现了,我不知道如何使用“setTimeout”来处理这个 observables,基本上只有在满足条件时才刷新那个时间。
有什么想法吗?
【问题讨论】: