首页 > ejs例子中的for循环出问题了

ejs例子中的for循环出问题了

如题所示,不知道是我自己写的原因还是什么问题

html代码:

    <h1>[%= title %]</h1>
    [% for(var i=0; i<supplies.length; i++){console.log(supplies[i])}%]
    <p>[%= supplies %]</p>

js代码

    window.onload = function(){
        var testObj = {    
            title: 'Cleaning Supplies',
            supplies: ['mop', 'broom', 'duster']    
        }
            
        dataDetailTemplate = new EJS({element: 'test-template'});
        result = dataDetailTemplate.render(testObj);
        document.getElementById('test').innerHTML = result;
    };

最后答应出来的结果:

如果改下html代码:
html代码:

    <h1>[%= title %]</h1>
    [% for(var i=0; i<supplies.length; i++){console.log(supplies[i])} %]
    <p>[%= supplies %]</p>

这里请注意下 console.log(supplies[i])}后面空了一格。这时候运行,浏览器的console会报错:

好奇怪,,望网上各路大神帮助,非常感谢~


EJS中间那行是干嘛的啊


输出不是应该这样?

<p>[%= supplies[i] %]</p>
【热门文章】
【热门文章】