سؤال

What is the use of Template.myTemplate.rendered in Meteor?. I had studied the document but i didn't understand the exact functionality.The document says Provide a callback when an instance of a template is rendered. What is the meaning of instance of a template is rendered.Can you please suggest me with an example?

هل كانت مفيدة؟

المحلول

When the callback is fired, an instance of the template has been rendered (added to the document). It can be useful if you for example want to manipulate the elements in the template through the use of a JavaScript library, for example CodeMirror, as I used in one of my projects. For example:

<template name="test">
    <textarea></textarea>
</template>
Template.test.rendered = function(){
    // Make the textarea highlight the code (kind of).
    var myCodeMirror = CodeMirror.fromTextArea(this.find('textarea'))
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top