I'm new to Durandal and haven't had much luck applying ko.computed methods inside of a viewmodel. Can someone tell me what the correct syntax or pattern is?
You can see the entire project at https://github.com/robksawyer/durandal-todo/blob/master/views/todos.html.
Each of the computeds that I apply gets the following error during a bind.
Error("Cannot write a value to a ko.computed unless you specify a 'write' option. If you wish to read the current value, don't pass any parameters.")
compose method requesting the viewmodel and view:
<!--ko compose: {
model: router.activeItem, //wiring the router
afterCompose: router.afterCompose, //wiring the router
cacheViews: false, //telling composition to keep views in the dom, and reuse them (only a good idea with singleton view models)
transition: 'fadein'
}--><!--/ko-->
viewmodel:
// count of all completed todos
var completedCount = ko.computed(function () {
return ko.utils.arrayFilter(todos(), function (todo) {
return todo.completed();
}).length;
});
view https://github.com/robksawyer/durandal-todo/blob/master/views/todos.html
Error screenshot