0

I have a view that renders its template into a named outlet. I use the didInsertElement hook, and there the afterRender schedule to wait for the DOM to complete. However, when I try to access the outcome of this render process, these elements are unknown. If I wrap the access in a setTimeout with time 0 (so that it runs in the next event loop cycle), it works.

App.PlaceView = Ember.View.extend({
    didInsertElement: function () {
        Ember.run.scheduleOnce('afterRender', this, function () {
            // This works
            setTimeout(
                function () {
                    // access elements
                },
                0
            );

            // Access elements here does not work
        });
    }
});

What am I doing wrong?

akohout
  • 1,802
  • 3
  • 23
  • 42
  • by any chance do you have any code running in didInsertElement or scheduleOnce??? – thecodejack Sep 17 '14 at 10:35
  • :D Yeah, I there is actual code that tries to get elements via jQuery. In the part where it works, I get the elements and can work with them as expected. On the place where it does not work jQuery does not return any element at all. – akohout Sep 17 '14 at 10:37
  • i meant you inserting DOM from some other child views thgh these methods(didInsert & scheduleOnce) which you are trying to access in this view. – thecodejack Sep 17 '14 at 10:40
  • Ok, i don't understand what you mean. I have a place Route, which renders an according template in an outlet and then triggers the PlaceView.didInsertElement. – akohout Sep 17 '14 at 10:45
  • could it be because you are using jquery grabbing stuff generated by another ember view? Maybe those views not ready? am guessing here tho.. could do with more detail in your question – charleetm Sep 19 '14 at 08:26

0 Answers0