D
D
dreamniker2016-02-27 20:17:44
JavaScript
dreamniker, 2016-02-27 20:17:44

How to call a function after rendering the entire template (including internal templates) or change the added tag with Javascript?

How to track when the rendering of the page has ended if the following construction is used:

<template name="creator">
{{#each banners}} 
{{> banner}} 
{{/each}}
</template>

The Template.creator.rendered and Template.creator.created helpers are called before all banners instances are rendered and if you call Template.banners.rendered it will be called many times instead of firing once at the end.

Or how to change the added tag using Javascript ?

<template name="banner">
    <textarea cols="33" rows="1" id="text1" style = "resize: none">{{group}}</textarea>
</template>


for each you need to call
$(textarea).height(textarea.scrollHeight);
(so that the height of the text field becomes equal to the height of the content and there is no scrolling)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
evilandfox, 2016-03-05
@evilandfox

You can use the hack with Meteor.defer. The function passed to it will be executed after the DOM is rendered:

Template.creator.onRendered(function(){
  Meteor.defer(function(){
    //Код
  });
});

in your case it will most likely be like this
Template.creator.onRendered(function(){
  Meteor.defer(function(){
    $('textarea').each(function(){
      $(this).height(this.scrollHeight);
    });
  });
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question