-4

問題:detectLocationtimersset()ロジックが機能していないようです。私はサブルーチンが実行されることを知っていますが、elseが間違っている場合は倍数だと思いますか?

detectLocationtimersset()の理由は、複数のタイマーが設定されないようにするためのロジックがあるためです。

最初にデータ時間に基づいてタイマーを設定するために最初のif/elseを作成し、次にセンスチェックを行うために2番目のif/elseを作成しました。

detectLocation()はテスト済みであり、それ自体で機能します。

var detectLocationtimerset = 0;
var datatime = 1;

function detectLocationtimersset() {    
    // Setup timer to check for new data start
    // check and see if set 
    if (detectLocationtimerset = 0 ) {
        detectLocationtimerset = 1;
        if (datatime == null) {
            datatime = 9;
            milliseconds = (datatime * 60000)
            setInterval(function () {
                detectLocation();
                console.log("detectLocation() timer set");
            }, milliseconds);   
        } else {
                    detectLocationtimerset = 1;
            milliseconds = (datatime * 60000)
            setInterval(function () {
                detectLocation();
                console.log("detectLocation() timer set");
            }, milliseconds);   
        }   
    }
};
4

2 に答える 2

4

何が問題なのかわかりませんが

if (detectLocationtimerset = 0 )

おそらく

if (detectLocationtimerset === 0)

その他の注意事項については、

  • インデントは一貫している必要があります
  • 演算子の周囲の間隔は一貫している必要があります
  • 可能な限り平等よりもアイデンティティを優先する必要があります
  • 共有コードをif/elseブロックから移動する必要があります—milliseconds割り当てを配置し、ブロックのsetIntervalに呼び出しますif (datatime == null)
于 2012-12-27T22:18:41.033 に答える
2

あなたの

if (detectLocationtimerset = 0 ) {

する必要があります

if (detectLocationtimerset === 0 ) {
于 2012-12-27T22:19:12.210 に答える