Take the 2-minute tour ×

I have Durandal viewmodel working like so:

define(function (require) {
var http = require('durandal/http');

return {
    subjectItem: function (data) {
        var self = this;
        self.Subject_ID = data.Subject_ID;
        self.Subject_Name = data.Subject_Name;
    subjects: ko.observableArray([]),
    activate: function () {
        var self = this;
        http.ajaxRequest("get", "/api/values/getsubjects")
            .done(function (allData) {
                var mappedSubjects = $.map(allData, function (list) { return new self.subjectItem(list); });

However, on first navigating to this view it runs the ajax call but does not change the dom, navigate to it again and they all appear (still runs ajax call). This is my html:

<tbody data-bind="foreach: subjects">
        <td data-bind="text: Subject_Name"></td>

Any clues, I'm very new to using Durandal but now worried it won't effectively keep the dom updated.

share|improve this question

1 Answer 1

up vote 6 down vote accepted

I think your problem is very similar to: HotTowel: Viewmodel lose mapping when navigating between pages

An AJAX call is an asyncronous task so you need to return a promise in the activate function for tell to durandal to wait until the data is retrieved before to proceed to apply bindings.

share|improve this answer
perfect, I simply put return at the start of my ajaxRequest call and now is there everytime, thanks. –  user1166905 Mar 14 '13 at 18:45

Your Answer


