Environment:
Ember.VERSION = 1.7.1
DS.VERSION = 1.0.0-beta.14.1
Problem: I'm trying to run some code when the view is finally rendered on initial application load, the problem is the model is not yet loaded because the client fetches it from the server.
so the flow (I guess) that happens is something like this:
- Ember renders the view, requests the model
- Model returns a promise but view is rendered anyhow
- After AJAX is finished model is updated and view is re rendered
I want to run some code (bootstrap init of tooltips) after step 3 is completed, but I dont really sure how to.
just to point out, after the model is fetched from server when I leave and return to the same route everything is works fine (because the model returns from the store and not from server)
what I tried so far:
How can catch event after template is rendered at EmberJS?
App.ApartmentsView = Ember.View.extend({
didInsertElement: function () {
$('[data-toggle="tooltip"]').tooltip();
}
});
this didnt work, because at that point the model length is 0
listening to model change:
App.ApartmentsRoute = Ember.Route.extend({
model: function () {
return this.store.filter('apartment').then(function (model) {
console.log(model);
return model;
});
}
});
Again, at this point the model.content.length = 0
I guess at this point the store just creates the model and only at a later point updates it.
I've also tried listening to the arrayContentDidChange
property in the controller, but at this point the model is not rendered yet, I can use a timeout but I think its a bad solution.
UPDATE1: here is the template:
<script type="text/x-handlebars" data-template-name="apartments" id="apartments">
.
.
{{#each }}
<tr>
<td>{{rating}}</td>
<td>{{price}}</td>
<td>{{street}} {{building}} {{city}}</td>
<td class="text-right hidden-print">
<button type="button" class="btn btn-default" aria-label="Left Align" data-toggle="tooltip" data-placement="top" title="Navigate" {{ action 'navigate' }}>
<span class="glyphicon glyphicon-transfer" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-default" aria-label="Left Align" data-toggle="tooltip" data-placement="top" title="Center Apartment" {{ action 'centerApartment' }}>
<span class="glyphicon glyphicon-screenshot" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-default" aria-label="Left Align" data-toggle="tooltip" data-placement="top" title="NOT WORKING" {{ action 'setTime' }}>
<span class="glyphicon glyphicon-time" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-default" aria-label="Left Align" data-toggle="tooltip" data-placement="top" title="NOT WORKING" {{ action 'share' }}>
<span class="glyphicon glyphicon-share-alt" aria-hidden="true"></span>
</button>
{{#link-to 'apartment' this classNames="btn btn-default"}}<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>{{/link-to}}
<div class="btn btn-default" data-toggle="tooltip" data-placement="top" title="Delete Apartment" {{action 'deleteApartment' }}>X</div>
</td>
</tr>
{{/each}}
.
.
</script>
Any suggestions?
tooltip
exists within theApartmentsView
and not in any childViews. If it does exist in childView, you need to wait until childViews finished rendering, or schedule initialization code withinEmber.run.scheduleOnce('afterRender', this, function() { // Yet more things });
– code-jaff