1
我是新来的JavaScript和库,所以这可能是一个简单的问题。我正在尝试使用handlebars.js模板引擎和jQuery来制作几个简单的网页。我一直在遇到的问题是制作多个页面。到目前为止,我有一个不同名称的主页。每个名称都有一个jQuery点击功能。如果我点击一个名称,我只是使用jQuery来更改当前页面。所以基本上,如果你点击一个名字,你会得到一个新的模板和一个该人的图片列表,但是在同一页上说index.html。这个问题是,如果你想回到第一个视图,“后退”按钮现在不起作用。我是否错误地构造了这个?链接应该发送到另一个页面和另一个模板?如果是的话,我该如何根据链接被按下来生成模板。与handlebars.js多个模板
$(document).ready(function(){
var source = $(".some-template").html();
var template = Handlebars.compile(source);
data = { date: "today", firstUsers: [
{firstName: "person1", pictures: ["pic1", "pic2", "pic3"]},
{firstName: "person2", pictures: ["pic1", "pic2", "pic3"]},
{firstName: "person3", pictures: ["pic1", "pic2", "pic3"]},
{firstName: "person4", pictures: ["pic1", "pic2", "pic3"]},
]
};
$(".container").html(template(data))
$("li").click(function(){
var name = $(this).html()
$.each(data.firstUsers, function(i, item){
if(name === item.firstName){
y = item.pictures
return y
};//if function
});//each function
$(".container").hide()
var source = $(".some-script").html();
var template = Handlebars.compile(source);
datas = {namer: name, pictures: y,}
//console.log(datas.pictures)
$(".content").html(template(datas))
});//click function
});//document ready