Javascript 未捕获类型错误:模板不是函数
我不确定为什么会出现此错误:Javascript 未捕获类型错误:模板不是函数,javascript,spacebars,Javascript,Spacebars,我不确定为什么会出现此错误: assignment.js:103 Uncaught TypeError: template is not a function 代码: 我使用空格键编译如下内容: $(document).ready(function() { // // compile all of our templates ready for use // var source = $("#category-template").html();
assignment.js:103 Uncaught TypeError: template is not a function
代码:
我使用空格键编译如下内容:
$(document).ready(function() {
//
// compile all of our templates ready for use
//
var source = $("#category-template").html();
category_template = SpacebarsCompiler.compile(source);
source = $("#animals-template").html();
animals_template = SpacebarsCompiler.compile(source);
source = $("#animal-template").html();
animal_template = SpacebarsCompiler.compile(source);
//
// clicking on the categorys tab shows the
// thumbnails of all the categorys
//
$("#category-tab").click(function () {
// displays the categorys template
showTemplate(category_template, animals_data);
// make the categorys tab the active one
// first make the currently active tab inactive
$(".nav-tabs .active").removeClass("active");
// then make categorys tab active
$("#category-tab").addClass("active");
$(".category-thumbnail").click(function (){
// get the index (position in the array)
// of the category we clicked on
// "this" is the element that was clicked on
// data("id") gets the attribute data-id
// (which we set to the index of the category in
// the array - @index)
var index = $(this).data("id");
// set the current category to this category
current_category = animals_data.category[index];
// displays the animals template
showTemplate(animals_template, current_category);
// add an on click al all the animal thumbnails
// which displays the animal in a modal popup
$(".animal-thumbnail").click(function (){
// get the index (position in the array)
// of the we clicked on
// "this" is the element that was clicked on
// data("id") gets the attribute data-id
// (which we set to the index of the animal in
// the array - @index)
var index = $(this).data("id");
// set the current animal to this animal
current_animal = current_category.animals[index];
// displays the single animal template
showTemplate(animal_template, current_animal);
});
});
});
$("#animal-tab").click(function () {
// displays the animals template
showTemplate(animals_template, current_category);
// make the animals tab the active one
// first make the currently active tab inactive
$(".nav-tabs .active").removeClass("active");
// then make animals tab active
$("#animal-tab").addClass("active");
// add an on click al all the animal thumbnails
// which displays the animal in a modal popup
$(".animal-thumbnail").click(function (){
// get the index (position in the array)
// of the animal we clicked on
// "this" is the element that was clicked on
// data("id") gets the attribute data-id
// (which we set to the index of the animal in
// the array - @index)
var index = $(this).data("id");
// set the current animal to this animal
current_animal = current_category.animals[index];
// displays the single animal template
showTemplate(animal_template, current_animal);
});
});
$("#category-tab").click();
});
在函数
showTemplate
中,正在调用参数template
。当您使用该函数时,是否将函数作为第一个参数传递?嗨,michel,是的,我是,奇怪的是,在Handlebar被弃用之前,它工作得很好,这是一个问题,因为我已经转到空格键。在您的函数showTemplate
中,正在调用参数template
。当你使用这个函数的时候,你是在传递一个函数作为第一个参数吗?嗨,米歇尔,是的,我是,奇怪的是,在车把被弃用之前,它工作得很好,这是一个问题,因为我已经转移到了空格键。
$(document).ready(function() {
//
// compile all of our templates ready for use
//
var source = $("#category-template").html();
category_template = SpacebarsCompiler.compile(source);
source = $("#animals-template").html();
animals_template = SpacebarsCompiler.compile(source);
source = $("#animal-template").html();
animal_template = SpacebarsCompiler.compile(source);
//
// clicking on the categorys tab shows the
// thumbnails of all the categorys
//
$("#category-tab").click(function () {
// displays the categorys template
showTemplate(category_template, animals_data);
// make the categorys tab the active one
// first make the currently active tab inactive
$(".nav-tabs .active").removeClass("active");
// then make categorys tab active
$("#category-tab").addClass("active");
$(".category-thumbnail").click(function (){
// get the index (position in the array)
// of the category we clicked on
// "this" is the element that was clicked on
// data("id") gets the attribute data-id
// (which we set to the index of the category in
// the array - @index)
var index = $(this).data("id");
// set the current category to this category
current_category = animals_data.category[index];
// displays the animals template
showTemplate(animals_template, current_category);
// add an on click al all the animal thumbnails
// which displays the animal in a modal popup
$(".animal-thumbnail").click(function (){
// get the index (position in the array)
// of the we clicked on
// "this" is the element that was clicked on
// data("id") gets the attribute data-id
// (which we set to the index of the animal in
// the array - @index)
var index = $(this).data("id");
// set the current animal to this animal
current_animal = current_category.animals[index];
// displays the single animal template
showTemplate(animal_template, current_animal);
});
});
});
$("#animal-tab").click(function () {
// displays the animals template
showTemplate(animals_template, current_category);
// make the animals tab the active one
// first make the currently active tab inactive
$(".nav-tabs .active").removeClass("active");
// then make animals tab active
$("#animal-tab").addClass("active");
// add an on click al all the animal thumbnails
// which displays the animal in a modal popup
$(".animal-thumbnail").click(function (){
// get the index (position in the array)
// of the animal we clicked on
// "this" is the element that was clicked on
// data("id") gets the attribute data-id
// (which we set to the index of the animal in
// the array - @index)
var index = $(this).data("id");
// set the current animal to this animal
current_animal = current_category.animals[index];
// displays the single animal template
showTemplate(animal_template, current_animal);
});
});
$("#category-tab").click();
});