简体   繁体   English

代码流未达到渲染功能

[英]Code flow doesn't reach the render function

ly In the following code, the render function is called in the loop below. ly在以下代码中,在下面的循环中调用render函数。 The wierd thing is that the line of code before the function call(console.log) works but the console.log directy inside the function doesn't work. 奇怪的是,函数调用(console.log)之前的代码行有效,但直接在函数内部的console.log不起作用。 check out the for(var i in coupons) line Moreover, the line after the function call doesn't work.console,log(e). 查看for(var i in coupons)行,此外,函数调用后的行不起作用。控制台,log(e)。 Also d is only executed once instead of 3 times as the length of the array is 3 I am unable to use the popup's console because it crashes my system(yes it actually does). 而且d仅执行一次,而不是执行3次,因为数组的长度是3。我无法使用弹出窗口的控制台,因为它使我的系统崩溃(是的,实际上确实如此)。 So I am having to rely on this. 所以我不得不依靠这个。

function render(template,object){
    chrome.extension.getBackgroundPage().console.log("Hello")//This doesn't
    var placeholders=/\$\{([A-Za-a0-9_]+)\}/.exec(template);
    chrome.extension.getBackgroundPage().console.log(placeholders);//Neither does this

}
function update(){
        chrome.extension.sendRequest({'action' : 'fetchCoupons'},
                function(couponsObj) {
                    // chrome.extension.getBackgroundPage().console.log('coupons');
                     //chrome.extension.getBackgroundPage().console.log($.tmpl);
                     var template=$("#coupons-template").html()
                   //$(".coupons").html(template    )
                   //$couponscontent=$.tmpl(template,coupons)
                    var coupons=couponsObj.coupons;
                    var deals=couponsObj.deals;
                         chrome.extension.getBackgroundPage().console.log(coupons);

                    for(i in coupons){
                        chrome.extension.getBackgroundPage().console.log("d");//This console.log works
                        render(template,coupouns[i]);//This line calls the render function
                        chrome.extension.getBackgroundPage().console.log("e");

                    }
                }
        );

}

        update();

You've got a typo which is causing the code to halt at the call to render : 您输入错误,导致代码在render调用时停止:

render(template,coupouns[i]);

Should be: 应该:

render(template,coupons[i]);

coupouns -> coupons 优惠券->优惠券

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM