[英]jquery loop conditional statement
How do I write a conditional statement for a jquery $.each loop? 如何为jquery $ .each循环编写条件语句? I tried to follow the suggestions at Is there conditional looping with $.each function in jQuery and other posts, however, I couldn't get it to work:
我试着按照jQuery和其他帖子中有$ .each函数的条件循环的建议,但是,我无法让它工作:
$.each((rgJson1["release-groups"]), function(index, item) {
var workTitle = item.title;
var pType = item['primary-type'];
var frDate = item['first-release-date'];
if (pType = "Album") {
console.log(workTitle);
}
});
When I tried that, it set the pType variable to "Album". 当我尝试时,它将pType变量设置为“Album”。 So, I tried:
所以,我尝试过:
if (item['primary-type'] = "Album") {
console.log(item.title);
But it still didn't work. 但它仍然没有奏效。 I also tried a variety of different combinations of brackets, quotes, and the like, but I haven't found a solution.
我也尝试了各种不同的括号,引号等组合,但我还没有找到解决方案。
try the following 尝试以下方法
if (item['primary-type'] === "Album")
or 要么
if (pType === "Album")
using just a single '=' will set the value, using '===' will check for congruency 只使用一个'='将设置值,使用'==='将检查一致性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.