2017-12-18 2 views
0
var checking_location = "none" 

const getentitiesByType = (arr, type) => { 
    for (let i in arr) { 
    if (arr[i].type === type) { 


     checking_location = "exists" 
     return arr[i].entity 
    } 
    } 
    return null; 
} 
if (!meeting.location) { 
    if (checking_location != 'exists') { 
    rl.question('where is the location ', function(answer) { 
     // session.send("The location you gave:" answer); 
     rl.close(); 
     session.send(answer) 
     // console.log(tryagain(answer, 'Calendar.Location')); 
     session.send(tryagain(answer, 'Calendar.Location')); 
    }); 
    } 
} else { 
    next(); 
} 

私がここでやろうとしているのは、checking_locationnoneに等しい場合、if (!meeting.location)にループを持つことです。基本的には、Jsonフィールドが存在するかどうかをチェックしたいのですが、もし私がrl.questionの質問をし続けたいのであれば、私の問題はコードが最初にしか動かないということです。必要なフィールドは私はその質問を取得しません。また、これはコード全体ではないことに注意してくださいが、私の実装で考えられる問題のスポットを理解する以上のものです。2番目のコードセクションに「if」が埋め込まれていないのはなぜですか?

+6

'getentitiesByType'は呼び出されず、ループを持つ唯一の場所です。 –

+0

私の悪い、私は2番目の埋め込みを意味する場合、私はそれを反映するために私の質問を調整します。 – Alex

答えて

1

getentitiesByTypeはどこかで呼び出す必要があります。単に変数に代入するだけでは、関数は実行されません。getentitiesByType(youArr, yourType)

また、checking_locationの文字列値を使用する代わりに、変数の名前を変更してブール値を使用するだけです。例:var hasLocation = false

関連する問題