问题描述:

I have an ember app which had code like this:

App.AccountListingsView = Ember.View.extend({

didInsertElement: function() {

console.log('did this fire');

}

});

Every time I transition into this view, it fires whatever is in the didInsertElement (This works fine) However... after loading the view, I'd like it to fire only once. I don't need it to fire every time I go back to this page/view.

Is there a better way to execute code so that it fires once after a view is rendered, and not again when you navigate off of that view and back to it again? As of now, if I go into another view and back to the listings view it fires again in the console.

网友答案:

No you can't. Wen transitioning the view gets destroyed and recreated when you come back. This will always get fired.

It's better to condition your actions based on some controller state.

相关阅读:
Top