TypeError:在Handlebars中未定义this._input

时间:2013-12-09 12:16:37

标签: handlebars.js

我添加了一个简单的Handlebar来获取JSON数据中的内容,但是我在控制台中收到此错误 - “TypeError:this._input is undefined”。我得到了正确的输出,但我总是得到这些错误..

<div class="profileSectionhandle">
     <script id="profileTabs" type="text/x-handlebars-template">
             {{#profilecontent}}
             .......
             {{/profilecontent}}
          </script>
     </div>

var source = $("#profileTabs").html();
var template = Handlebars.compile(source);
$(".profileSectionhandle").html(template(data));

1 个答案:

答案 0 :(得分:0)

如果你是console.log(source),那么它将返回undefined。这意味着我的代码运行时$("#profileTabs").html()不在DOM中,然后您尝试编译undefined

有可能在你的js调用把手时你的页面没有被加载。如果您正在使用Web应用程序(使用jquery),则将您的函数放在$(document).ready(function () {...})中;对于移动应用程序(使用jquery mobile),可以将$( document ).bind( "pagebeforeshow", function() {...})放在// Pace function getPace() { $dis_pace = $this->distance / 1000; $pace = $this->totaltime / $dis_pace / 60; return $pace; }

相关问题