简体   繁体   中英

Cannot call method 'match' of undefined handlebar issue

I have my template with handlebar and is working the most quantity of time but sometimes give me this error Cannot call method 'match' of undefined. This is my code

view

      <div id="template"></div>
            <script id="template-script" type="text/x-handlebars-template">  
                {{#measures_list}}      
                    <div class="col-lg-7  col-lg-offset-1">                     
                            <p class="indicator-title gray-bottom-border">{{name}}</br></p>
                            <div>
                                <p><span class="font30px">{{total}} </span> Total {{name}}<br><span class="green-text">{{increase}}%</span> from last <span class="metric_time"></span></p>
                            </div>
                            <div class="graph-header">
                                <h3>{{this_interval}} </h3><p>New {{name}}</p>
                                <p class="percentage-graph green-text">{{percentage}}%<p>
                            </div>                      
                        <div id={{graph_id}} class="graph"></div>

                    </div>
                {{/measures_list}} 
            </script>

js

   var source=$("#template-script").html();
   var template=Handlebars.compile(source);
   $('#template').empty().append(template(template_data));
   console.log('source'+source+'template'+template)

I use the console.log to see the error, so many times work perfectly but in somme case source is undefined, the page appears many times, for example I click on a button and appears after I close the page and click on the button again and do that many times, after many times or after the first time give me the error: Cannot call method 'match' of undefined

Any help please

var source=$("#template-script").html() || '';

我把所有脚本标签都放在我的js中,就像一个变量而被调用而不是源代码,我的修复是因为有时候无法找到是在那里,所以我改为我的js并且正在工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM