Question

Below is a hottowel viewmodel. I am trying to figure out where and how to place a jquery call

define(['services/logger'], function (logger) {
    var vm = {
        activate: activate,
        title: 'Applications'
    };

    return vm;

    //#region Internal Methods
    function activate() {
        logger.log('Applications', null, 'applications', true);
        return true;
    }
    //#endregion
});
Was it helpful?

Solution 2

Depends on where you want it to run. If you want the jquery code to execute when the viewmodel activates, then put it in the activate method. if you want it to run once, when the viewmodel is created, put it before the return statement.

OTHER TIPS

What I want to know is "why do you want jQuery in your ViewModel?" jQuery is for DOM manipulation. Well we have KO to that for us with binding. We shouldn't need jQuery. The use of jQuery in a ViewModel is usually (not always) a code smell. My rule of thumb is "if I'm using jQuery, I'm doing it wrong."

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top