我正在尝试通过检查电影是否具有相同的发行日期,相同的标题以及是否在记录到数据库之前是否属于同一类别,来检查该电影是否已在数据库中。我确定这样做是错误的,并且不知道如何对多个条件或嵌套的if进行检查。
for(var i = 0; i < moviesJSON.results.length; i++) {
var movie = moviesJSON.results[i];
// check for release date
moviesDb.orderByChild('release_date').equalTo(movie.release_date).once('value', function(snapshot) {
if(snapshot.exists()) {
console.log('same release date');
// if same release date, check for title
moviesDb.orderByChild('title').equalTo(movie.title).once('value', function(snapshot) {
if(snapshot.exists()) {
// if same release date and title, check for category
moviesDb.orderByChild('category').equalTo(optionCategory).once('value', function(snapshot) {
if(snapshot.exists()) {
// data already in database, do nothing
console.log('movie info already in database, do nothing!!!!');
} else {
// category is different, update database and change category
console.log('update category for title: ' + movie.title);
}
});
} else {
// same release date, but different movie, add to database
console.log('same release date, but different title, add to database!!!');
}
});
非常感谢您的帮助。谢谢大家