3

Inside my list of completed tasks, I used Moment.js's fromNow() to list the relative date of completion for each task. Here's the task model:

Task.Model = function(data) { this.id = data.id; this.title = ko.observable(data.title); this.status = ko.observable(data.status); this.completed = ko.observable(moment(data.date_completed).fromNow()); }; 

The relative date shows up, but the minutes never update, unless I refresh. Is there any way to update that observable?

1
  • What do you mean on "never update, unless I refresh"? Who and why should update it? How do you "refresh" the browser with F5? Commented Aug 31, 2013 at 20:20

1 Answer 1

9

You could have an observable which tracks the current time, then compute the completed text based on that time:

var now = ko.observable(new Date()); setInterval(function() { now(new Date()); }, 60 * 1000); var completedText = ko.computed(function() moment(data.date_completed).from(now())); }); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.