简体   繁体   English

无法调用未定义车把问题的方法'匹配'

[英]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. 我有我的模板与车把,工作时间最多,但有时给我这个错误不能调用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 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 我使用console.log来查看错误,因此很多次工作都很完美,但是在somme情况下来源未定义,页面出现很多次,例如我单击一个按钮并在关闭页面后再次单击按钮后出现做了很多次,经过多次或第一次给我错误之后: 不能调用undefined的方法'匹配'

Any help please 请帮忙

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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