我试图在代码下面运行,但它抛出错误。似乎在handlebar.compile中我传递了null(a [j]),我认为这是因为控制没有进入.when的功能,因为我没有看到任何登录控制台。我可能错了。但请帮我纠正它。
代码:
if (pageName.page === "dashboard") {
$.getJSON('api/filterTemplate/dashboard',function (data){
var a = new Array(data.length);
console.log(data);
$.when(function(){
console.log("inside function 1");
for (var i = 0; i < data.length;) {
console.log("inside funct 1 for loop");
$.get('commonCore/templates/' + data[i].templateHtml , function(html) {
a[i]=html;
i++;
console.log("inside funct 2" + i +" " + html);
});
}
}).then(function(d) {
for (var j = 0;j < data.length; j++) {
filterTemplate = Handlebars.compile(a[j]);
replaceFilterTemplate(data[i].classids);
}
});
});
}
JSON:
[
{
"templateHtml": "dashBoardLeftInsight.html",
"classSelect": "leftpanel"
},
{
"templateHtml": "dcdcsFilterOptions.html",
"classSelect": "dcdcsOptions"
},
{
"templateHtml": "advanceFilterOptions.html",
"classSelect": "advancedOptions"
},
{
"templateHtml": "reportFilterOptions.html",
"classSelect": "reportdashboard"
}
]