I am using KnockoutJS to bind some values. I have a date value TimeByDay
that I bind like this:
<span data-bind="text: new Date(TimeByDay)"></span>
But I would also like to transform the date on a different location and simply add a day to the TimeByDay
value.
I can do it like this:
<span data-bind="text: new Date(new Date(TimeByDay).setDate(new Date(TimeByDay).getDate() + 1))"></span>
Is there a prettier way to do this? Maybe some feature in KnockoutJS that I am missing?
(The reason I am encapsulating both values in a new Date() construct is that I also apply formatting to the date.)
ViewModel:
$(document).ready(function () {
var serverData = $.getJSON("../../_api/");
serverData.done(function (data) {
ko.applyBindings(new EngagementsList(data.value));
});
});
function EngagementsList(engagementList) {
var self = this;
self.entries = engagementList;
}
HTML:
<span data-bind="foreach: entries">
<span data-bind="text: new Date(TimeByDay)"></span>
<span data-bind="text: new Date(new Date(TimeByDay).setDate(new Date(TimeByDay).getDate() + 1))"></span>
</span>