2015-09-06 5 views
3

Вот мой HTML:Uncaught TypeError: Handlebars.compile не является функцией

<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> 

А вот мой ЯШ:

var userPaymentTypeRight = $('#rowUserPaymentTypeRight').html(); 
var userPaymentTypeRightTpl = Handlebars.compile(userPaymentTypeRight); 
var context = data; 
var html = userPaymentTypeRightTpl(context); 
$('#tableUserPaymentTypeRight').html(html); 

данных, как это:

{ 
{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} 
} 

Кажется правильным в соответствии с API, bu t Я только что получил ошибку: Uncaught TypeError: Handlebars.compile не является функцией.

+0

Определяется ли рулевая колонка? Как насчет Handlebars.compile? У меня есть тот же код, что и у вас, но я использую requirejs для его загрузки. Возможно, образец кода, на который вы смотрели, также загружал его через загрузчик модуля, например requirejs? Сначала я рассмотрю механизм включения include/load/script. –

+0

Я также использовал requirejs для его загрузки, –

+0

, как выглядит ваш ** define **? Это было мое ** define (['bootstrap', 'jquery', "handlebars"], function (bootstrap, $, Handlebars) {**. Работает ли панель firefox/chrome dev на вкладке Net, что GET для рулей работает? –

ответ

0

Что

console.log(Handlebars.compile) 

шоу?

Совершено на консоли Firefox Firebug, шахта показывает:

function(input, options) 

И console.dir рулей? Mine:

console.dir(Handlebars) 

выход:

helpers Object { helperMissing=function(), blockHelperMissing=function(), each=function(), more...} 

....

VERSION  "1.3.0" 

....

compile function(input, options) 
+0

Это не определено. Возможно, есть проблема с получением запроса для handlebars.js. –

+0

Исключение: Исключение (сообщение, узел) HandlebarsEnvironment: HandlebarsEnvironment (хелперов, обертоны) REVISION_CHANGES: Object SafeString: SafeString (строка) Utils: Object VERSION: "2.0.0" VM: Object создать:() createFrame: (объект) default: HandlebarsEnvironment escapeExpression: escapeExpression (строка) помощники: объект журнал: (уровень, сообщение) логгер: Объект частичные: Объект шаблон: (spec) –

+0

его странно, что в этой версии нет функции complie. –

0

Вам нужно включить handlebars.amd.js вместо этого.

Если у вас есть узел, перейдите в папку Темп типа

npm install --save handlebars

идти в \node_modules\handlebars\dist\

копия файла handlebars.amd.js в свой проект.

Смежные вопросы