gulp-file-include icon indicating copy to clipboard operation
gulp-file-include copied to clipboard

The variable is not defined

Open hooray opened this issue 6 years ago • 5 comments

<header>
    @@for(var i = 0; i < button.length; i++){
        @@if(button[i].type == "return"){
            <a href="javascript:;" class="return `+button[i].position+`">
                <i class="fa fa-chevron-left"></i>
            </a>
        }
        @@if(button[i].type == "search"){
            <a href="@@webRoot/search.html" class="search `+button[i].position+`">
                <i class="fa fa-chevron-left"></i>
            </a>
        }
    }
    <span class="title">@@title</span>
</header>

Error Info: i is not defined: (button[i].type == "return")

hooray avatar Mar 06 '18 09:03 hooray

You can try do this:

`+(i == 0 ? '[yes, todo]' : '[no, todo]')+`
<header>
    @@for(var i = 0; i < button.length; i++){
        `+(button[i].type == "return" ? '<a href="javascript:;" class="return '+ button[i].position +'"><i class="fa fa-chevron-left"></i></a>' : '')+`
        ...
    }
    <span class="title">@@title</span>
</header>

The solution:https://hooray.github.io/posts/5f8cb75e/

Keystion avatar May 29 '18 14:05 Keystion

@Keystion lol, the link you shared is my blog, the solution can solve my problem, but I don't think it is the best way. ^_^

hooray avatar May 30 '18 08:05 hooray

@hooray [Laugh & Cry], The careless.

Keystion avatar Jun 04 '18 06:06 Keystion

I have been in contact with gulp for a few days, and now I am working on the project with gulp.I encountered the problem of using if in the loop. I judged that the format was similar to the code of the main building.Looked at the host's blog just know originally I have written three yuan problem (^ o ^)

error demo: http://t.cn/RBk8K2M

我刚接触gulp几天,现在正在用gulp做项目。遇到了循环中使用if的问题,判断格式跟楼主的代码相似,结果报错了,也尝试过三元,结果直接输出。看了楼主的博客才知道原来我三元写的有问题(^o^) 【不会英语,x道翻译的凑合用吧,链接是示例代码链接】

yilingsj avatar Jun 20 '18 10:06 yilingsj

Succeeded ! demo : + (item[i].txt ? '<p class="txt">'+item[i].txt+'</p>' : "") +

yilingsj avatar Jun 20 '18 10:06 yilingsj