NodeJS在请求

时间:2018-01-12 09:57:04

标签: javascript arrays node.js loops express

我们编写了一些从数据库返回数组的代码,在第一次请求时,我们遍历它直到找到变量。然后发送该值。

但是,如果我们还有第二个请求请求开始在该位置进行迭代,那么我们就会离开上一个循环。

result.findAllLights(function (lights) {
            console.log("got callback");
            var send = false;
            delete lightId;
            console.log("PRE-LOOP = " + JSON.stringify(lights));


            for (var lightId in lights) {
                console.log("checking " + lightId);

这会产生

checking 0
light.column=0 and row = 0 and 1 and 1
checking 1
light.column=0 and row = 1 and 1 and 1
checking 2
light.column=0 and row = 2 and 1 and 1
checking 3
light.column=0 and row = 3 and 1 and 1
checking 4
light.column=0 and row = 4 and 1 and 1
checking 5
light.column=1 and row = 0 and 1 and 1
checking 6
light.column=1 and row = 1 and 1 and 1
found light

当第二个请求在此时是输出

checking 7
light.column=1 and row = 2 and 1 and 1
checking 8
light.column=1 and row = 3 and 1 and 1
checking 9
light.column=1 and row = 4 and 1 and 1
checking 10
light.column=2 and row = 0 and 1 and 1
checking 11
light.column=2 and row = 1 and 1 and 1
checking 12
light.column=2 and row = 2 and 1 and 1
checking 13
light.column=2 and row = 3 and 1 and 1
checking 14

0 个答案:

没有答案