在我的程序中,我从控制台获取数据并将其存储在localstorage和webSQL中。现在我想使用handlebar显示来自localstorage的存储数据。我使用了以下代码:
console.log(response); // To get data from console
var offer = JSON.stringify(response);
localStorage.setItem("object",offer); // saved in localstorage
var seasons= localStorage.getItem("object"); // get data from localstorage and saved in variable seasons
var mysource = document.getElementById("detailstemplate").innerHTML;
var mytemplate = Handlebars.compile(mysource);
var myresult = mytemplate(seasons);
document.getElementById("divOffers").innerHTML = myresult;
我使用最后4行来使用把手显示数据。但它没有用。请更正错误。任何人都可以帮忙解决这个问题吗?
答案 0 :(得分:0)
var season = localStorage.getItem("cart");
var season2 = $.parseJSON(season);
var mytemp = $("#mainmenu-template").html(); // Grab the template script
var ourtemp = Handlebars.compile(mytemp); // Compile the template
var resultnew = ourtemp(season2);
$("#divMainMenu").append(resultnew);