【发布时间】:2015-09-27 14:35:07
【问题描述】:
在激活我的编辑视图页面时,我正在尝试使用外键从不同的表中获取实体,但我认为这不是获取和更新实体的正确方法,它不会保存更新的属性“modification_date”和我面临的另一个问题是时间问题,因为我有一个属性“startDate”,它是日期时间类型,所以当我将我的应用程序托管到某个 VM 时,它显示的时间是 +5:30 的时间原始值,因为数据库将值存储在 GMT +00:00 中。我怎么解决这个问题? 我的问题是:
- 为什么“modification_date”不保存当前日期,无论何时更新实体。
<input data-bind="value: modificationDate = $root.md, visible: false"
>
Javascript
vm.md = ko.dependentObservable(function () {
var y = new Date();// should assign current to modification date but its not persisting the changes to database.
return y;
}, vm);
当我的当前时间是 GMT +5:30 时,如何向客户端显示 GMT +00:00 的正确时间。在从 SqlServer 编辑和获取数据时。
请评论我们如何使用导航键访问另一个表,因为我正在做的是获得一个可观察的“作业”,并且存在不同的属性,另一个表是“job_Schedule”,所以我应该怎么做访问“job_Schedule”表下的属性 startDate。目前我正在访问的是
job_Schedule._latestValue[0].startDate,这可能不是获取实体的正确方法。
这是我的一段代码:
<div data-bind="with: job">
<label>Start Date :</label>
<input data-bind="kendoDateTimePicker: $root.temp3" />
<input data-bind="value: job_Schedule._latestValue[0].startDate = $root.tempSD1, visible: false" />
<input data-bind="value: modificationDate = $root.md, visible: false" >
//I kept visible: false because modified date should be updated automatically
// some more attributes................
</div>
Javascript 代码
vm.md = ko.dependentObservable(function () {
var y = new Date();// should assign current to modification date but its not persisting the changes to database.
return y;
}, vm);
vm.tempSD = ko.dependentObservable(function () {
var y = ko.unwrap(this.tempx());// tempx containing the current value of startDate
if (y === null || y === '""') { y = new Date(); }
y = new Date(y);
var utc = y.getTime() + (y.getTimezoneOffset() * 60000);
temp3(new Date(utc));
return new Date(utc);
}, vm);
vm.tempSD1 = ko.computed(function () {
var y = vm.temp3();
if (y === null || y === '""') {y = new Date();}
y = new Date(y);
var utc = y.getTime() - (y.getTimezoneOffset() * 60000);
return new Date(utc);
},vm);
【问题讨论】:
-
什么是修改日期?为什么要在绑定表达式而不是 JavaScript 中设置它?
-
那我该如何在javaScript中实现呢?因为“modificationDate”是数据库中的一列。
-
vm.job.modificationDate(new Date());假设 vm.job 是具有modificationDate属性的 Breeze 实体。 -
不,我们不能那样做,我已经试过了,它会显示错误
Failed to load routed module (viewmodels/jobedit). Details: vm.job.modificationDate is not a function -
啊,我看到 vm.job 是一个 observable。所以应该是
vm.job().modificationDate(new Date());
标签: knockout.js breeze hottowel