未捕获的TypeError:Handlebars.compile不是函数

冯奕轩*_*冯奕轩 5 handlebars.js

这是我的HTML:

<table id="tableUserPaymentTypeRight">
     <col width="50%"/>
     <col width="25%"/>
     <col width="25%"/>
     <script id="rowUserPaymentTypeRight" type="text/x-handlebars-template">
          {{#each Data}}
              <tr>
                 <td>{{FullName}}</td>
                 <td>
                     {{#if Right_Add}}
                          <input type="checkbox" value="{{UserID}}_0" checked/>
                     {{else}}
                          <input type="checkbox" value="{{UserID}}_0"/>
                 </td>
                 <td>
                      {{#if Right_Confirm}}
                          <input type="checkbox" value="{{UserID}}_1" checked/>
                      {{else}}
                          <input type="checkbox" value="{{UserID}}_1"/>
                 </td>
            </tr>
       {{/each}}
</script>
Run Code Online (Sandbox Code Playgroud)

这是我的js:

var userPaymentTypeRight = $('#rowUserPaymentTypeRight').html();
var userPaymentTypeRightTpl = Handlebars.compile(userPaymentTypeRight);
var context = data;
var html = userPaymentTypeRightTpl(context);
$('#tableUserPaymentTypeRight').html(html);
Run Code Online (Sandbox Code Playgroud)

像这样的数据:

{
{UserID: 26031, FullName: "Aaron Zubler", Right_Add: null, Right_Confirm:null, RowIndex: 1},
{UserID: 26390, FullName: "Achilleas Hoppas", Right_Add: null, Right_Confirm: null, RowIndex: 2},
{UserID: 26168, FullName: "Ai Ke", Right_Add: null, Right_Confirm: null, RowIndex: 3},
{UserID: 26310, FullName: "Alessandra Giordanella", Right_Add: null, Right_Confirm: null, RowIndex: 4}
}
Run Code Online (Sandbox Code Playgroud)

根据API似乎是正确的,但我得到了错误:Uncaught TypeError:Handlebars.compile不是一个函数.

And*_* RB 5

就我而言,发生错误是因为我使用的是运行时版本的把手。由于我不打算预编译我的模板(不推荐),所以我已转移到普通版本。

@JL Peyret 提供的答案帮助我找到了真正的问题。


JL *_*ret 0

什么是

console.log(Handlebars.compile)
Run Code Online (Sandbox Code Playgroud)

展示?

在 Firefox Firebug 控制台上完成,我的显示:

function(input, options)
Run Code Online (Sandbox Code Playgroud)

还有 Handlebars 的 console.dir 吗?矿:

console.dir(Handlebars)
Run Code Online (Sandbox Code Playgroud)

输出:

helpers   Object { helperMissing=function(),  blockHelperMissing=function(),  each=function(),  more...}
Run Code Online (Sandbox Code Playgroud)

....

VERSION     "1.3.0"
Run Code Online (Sandbox Code Playgroud)

....

compile  function(input, options)  
Run Code Online (Sandbox Code Playgroud)