javascript - Call Function on View Loaded (Activate) in Hot Towel/Durandal Single Page App -


i'm using hot towel spa project i'm trying call simple js function when view activated. i'm seeing item not seem loaded when activate function called.

i've tried putting code in initialize function called activate suggested on other posts. not seem help.

so recommended method in durandal/hottowel calling function on view load?

home.js (view model)

define(['services/logger'], function (logger) {     var vm = {         activate: activate,         title: 'home'     };      return vm;      function activate() {                logger.log('home view activated', null, 'home', true);         return init();     }      function init() {         $("#backbtn").hide();         console.log($("#mybtn").html()); // returns undefined      } }); 

home.html (view)

<section>     <div id="mybtn">test</div> </section> 

when durandal attaches view model looks on model viewattached method. modified code below. should find jquery elements looking for.

define(['services/logger'], function (logger) {     var vm = {         activate: activate,         viewattached: viewattached         title: 'home'     };      return vm;      function activate() {                logger.log('home view activated', null, 'home', true);     }      function viewattached(view) {         $(view).find("#backbtn").hide();         console.log($(view).find("#mybtn").html());      } }); 

take @ composition page @ bottom little more viewattached. http://durandaljs.com/documentation/using-composition.html


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -