Durandal Custom View Location Strategy

Viewed 743

I am trying to figure out how to use a custom view location strategy, I have read the documentation at this page http://durandaljs.com/documentation/Using-Composition/ but I don't exactly understand what the strategy function should look like.

Can anybody give me a quick example of what the implementation of this function would be like and the promise that returns (even a simple one) etc?

Thanks in advance, Gary

p.s. This is the code in my html:

 <div>
     <div data-bind="compose: {model: 'viewmodels/childRouter/first/simpleModel', strategy:
 'viewmodels/childRouter/first/myCustomViewStrategy'}"></div> </div>

and this is the code in my myCustomViewStrategy:

define(function () {

    var myCustomViewStrategy = function () {

        var deferred = $.Deferred();

        deferred.done(function () { console.log('done'); return 'simpleModelView'; });
        deferred.fail(function () { console.log('error'); });

        setTimeout(function () { deferred.resolve('done'); }, 5000);

        return deferred.promise();
    };

return myCustomViewStrategy;
});

but I get the error:

Uncaught TypeError: Cannot read property 'display' of undefined - this is after done has been logged in the console window.

2 Answers
Related