javascript - How to run function when route is loaded? -
i want have myfunk()
run when overview route loaded onto page, , when go somewhere else , come back, myfunk()
run again, have no model overview view, tried use didinsertelement
dont know if makes sense.
app.js:
app.router.map( function() { this.resource('overview'); }); app.overviewview = ember.view.extend({ didinsertelement: function() { myfunk(); } });
index.html:
<script type="text/x-handlebars" data-template-name="application"> <div id="wrapper" class="clearfix"> <div id="content" class="clearfix"> {{outlet}} </div> </div> </script>
and route template:
<script type="text/x-handlebars" data-template-name="overview"> <div class="leftbox"> <img id="kpibox" src="../img/kpis.png" /> </div> </script>
you hook activate
, deactivate
correspondently have function run when route enters or exits.
depending on myfunc()
lives, let's in app.overviewcontroller
(but in different controller) following:
app.overviewcontroller = ember.objectcontroller.extend({ myfunc: function() { // stuff } }); app.overviewroute = ember.route.extend({ activate: function() { this.controllerfor('overview').send('myfunc'); } });
if need pass parameters myfunc()
include them so:
this.controllerfor('overview').send('myfunc', param);
hope helps.
Comments
Post a Comment