2017-05-01 14 views
0

現在、私はwatson chatbot対話アプリケーションを使って作業しています。私はコンテキストをリフレッシュしなければならない状況に遭遇しました。ユーザーの入力に応じて特定の段階でちょうど完了しましたが、これを達成できませんでした。ワトソン対話コンテキスト

I tried setting the context = {}, if the user input isn't in the Array, but it seems to check the context at every stage of the Application. 

if(context.city !== array[i]['city']){ 
     context = {}; 
} 

what i am asking the user is to input a list of cities, which is in an Array. If the user inputs a location that isn't in the Array first, it let's the user know that it isn't in the Array. If the user inputs a city that is not in the Array after inputing a city that is already in the array, it is returning the last context. 

for example, 

City = Boston. 
You just input Boston, price is 20. 
Then if i do City = Atlanta(Bearing in mind Atlanta is not in the Array) 
it does city is Atlanta, price is 20. 

Any idea how to fix this, on any steps i can follow to stop this from happening? 

答えて

0

あなたは enter image description here あなたのアプリや高度なエディタで空の文字列またはnullにcontext.cityを設定し、アプリの修正ロジックでいるかもしれない他の誰かのためにその

+0

ありがとう、私は実際にこれを投稿してから約10分後にそれを行う方法を考え出しました。ありがとうございました。 –

1
for(var i = 0; i < array.length; i++){ 
    if (context.city !== array[i]['city']){ 
    if(inputBox.value === context.city) 
    { 
    context = latestResponse.context; 
    context.rate = rate; 
    context.currency = currency; 
    } 
    else 
    { 
     context.city = ""; 
     context.rate = ""; 
     context.currency = ""; 
    } 
    } 
} 

に基づくことができます今または将来同じ問題が発生する可能性があります。

これは私のために解決されました。必要な情報はArray内にあったので、ループしてcontext.city!=配列かどうかを調べました。

関連する問題