ember.js route render: dom manipulation with setTimeout()? -
If I wanted to call a jquery plugin (for example, puts it in a table dom) after a scene, Is there a prospect in addition to doing this with window.Settimeout ()?
This code works (1 mms timeout; strange;)
root.Homereate = amber .Route.extend ({renderTemplate: function () {this. Render ("home"); // home view window .set timeout (function () ($ (".tables"). InsertTables (); // it must be added to a table}, 1);}}) But this code does not work:
root.Homereate = amber.out.andend {{RenderTemplate: function () {this.render ( "Home"); // home view $ (".tables"). Insert (); // it will add a table}}); I know that there are Ember .View.didInsertElem Ent (), but so I have to set a callback on the parents' view, and just wondering why the above code example does not work as expected.
Many thanks! < / P>
I do not know my answer is 100% correct, but I think how it can be explained I think the problem is that, you think that the render () method coordinates your work but this is not the situation Land. Instead, it determines the timing of the homeview rendering, rendering in Amber's Run Loop . In the second example, your code renders the rendering and then immediately tries to use its own DOM elements (I think Tables is part of the Home Template). But this time this view has not been translated! The first example works because it contains 1ms timeout. During this time, the amber run will kick the loop and start its magic. Your rendering time can be called while rendering and later when the CPU is free again. Actually you want to do this here: Do something on my dom, when the view was successfully provided . This can be done in Amber without the use of set-timeout, the following code reaches the clutter and schedules a function to do at the end of the rails. Ember.run.next (function () {$ ("Table"). InsertTables (); // This will add a table}}; Here is an article on RunLoop, which is important to understand, if you want to understand the details of Amber: -
Last but not least: This route In this, it is completely strange to manipulate the DOM. Your root should always be free of such things. Elements and selectors and jQuery plugins should be used only in the scene layer. Everything else may feel bad that you chose this approach? It is likely to have a better solution.
Comments
Post a Comment