gulp-file-include
gulp-file-include copied to clipboard
The variable is not defined
<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")
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 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 [Laugh & Cry], The careless.
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道翻译的凑合用吧,链接是示例代码链接】
Succeeded !
demo : + (item[i].txt ? '<p class="txt">'+item[i].txt+'</p>' : "") +