2016-11-27 6 views
0

リストをチェックするコードを書いて、リスト内の各項目が他の項目に存在するかどうかを確認します。アイテムが見つからない場合、アイテムはデータベースに追加されます。コードが完全なスクリプトを実行していない

スキャンコードは正しいです(db.scanという部分)が、console.logの部分を実行していないためコードが通過していません。私はこのコードを実行すると。 「の記事のタイトルは」、何も起こりません。少なくとも、エラーはありません...しかし、何かが間違っているように、そのさえにconsole.log部品をロギングない。

// accessing the database 
function DatabaseTime(sourcesDates, timeAdded, links, titles, descriptions) { 
    sourcesDates = sourcesDates; 
    links = links; 
    titles = titles;  // this will be used to check on our articles 
    descriptions = descriptions; 

    var autoParams; 
    var databaseOperation = function (sourcesDates, timeAdded, links, titles, descriptions) { 
     var scanParams = { TableName: "Rnews" } 
      // using code to setup for accessing the 2nd list 
      db.scan(scanParams, function(err, scanData) { // scanData = the 2nd list we are going to work with 
       var counter = 0; // just a way to help make my code more accurate as seen later in the loops 
       var counter2 = 0; 
       // this is the first list iterating on 
       for (var i = 0; i < links.length; i++) { 
        counter = 0; 
        // looping through items in second list 
        for (var x = 0; x < scanData.Items.length; x++) { 
         // if article is not in db 
         if (titles[i] !== scanData.Items[x].title) { 
          continue; 
         } 
         else if (titles[i] === scanData.Items[x].title) { 
          // intention is to immediately move to the next item in the first list if this block executes 
          console.log("Article found: \"" + titles[i] + "\". Not proceeding anymore with article."); 
          counter++; 
          break; 
         } else { 
          // if this article isnt found anywhere in the list we are checking on, add to database 
          if (x === scanData.Items.length && counter !== 0) { 
           autoParams = { 
            TableName: "Rnews", 
            Item: { 
             title: titles[i], 
             source: sourcesDates[i], 
             url: links[i], 
             description: descriptions[i], 
             lastAddOrUpdated: dbTimeStamp, 
             timePublish: timeAdded[i] 
            } 
           } 
           console.log("Entering journal to database: " + titles[i]); 
           db.put(autoParams, function(err, data) { 
            if(err) throw err; 
           }); 
          //} 
         } 
        } 
       } 
      } 
      }); 
     //console.log("Complete"); 
    }; 
    databaseOperation(sourcesDates, timeAdded, links, titles, descriptions); 
} 
//// END 
+1

デバッガを使用してコードをステップ実行し、失敗した箇所を確認します。 (['node-inspector'](https://www.npmjs.com/package/node-inspector)は、NodeJS用のデバッガの1つです) –

+0

私はそれを試していただきありがとうございます – Chris

+0

プロのヒント:それがどれほど素晴らしいかのグラフではありません。このコードについて簡単に考えることは不可能です。 –

答えて

0

ます関数DatabaseTimeを呼び出すことはありません。あなたのコードは単に関数を宣言し、それ以外は何もしません。関数を実行するには、それを呼び出す必要があります。

関連する問題