Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 多维数组与时间戳_Javascript_Jquery_Multidimensional Array_Google Calendar Api - Fatal编程技术网

Javascript 多维数组与时间戳

Javascript 多维数组与时间戳,javascript,jquery,multidimensional-array,google-calendar-api,Javascript,Jquery,Multidimensional Array,Google Calendar Api,代码如下: var array = []; $('.body-watch-logo').each(function () { array[]['evendId'] = $(this).data('event'); array[]['timestamp'] = $(this).data('timestamp'); $now = new Date(); $outStr

代码如下:

var array = [];

$('.body-watch-logo').each(function () {

                array[]['evendId'] = $(this).data('event');
                array[]['timestamp'] = $(this).data('timestamp');

                $now = new Date();
                $outStr = now.getHours()+':'+now.getMinutes();

                alert($outStr);

                if(array[]['timestamp'] == $outStr) {

                        alert('Tring Tring Tring');

                        //do something here

                }

                $i++;
        });

.body watch徽标中包含多个事件,属性为eventId和startTime。所以我想把这些信息存储在数组中。然后将只有小时和分钟的开始时间与当前时间进行比较。如果两者相等,则发出警报。有人知道怎么做吗?可能需要使用Ajax。请建议。

您增加了
i
,但从未初始化它或将其用作数组索引。但是您也不需要这样做,因为
.each()
将索引作为参数传递给迭代函数。看

数组的元素更好地实现为对象,而不是子数组

var array = [];

$('.body-watch-logo').each(function (i) {
    array[i] = { event: $(this).data('event'),
                 timestamp: $(this).data('timestamp')
               };

    $now = new Date();
    $outStr = now.getHours()+':'+now.getMinutes();

    alert($outStr);

    if(array[i].timestamp == $outStr) {
            alert('Tring Tring Tring');
            //do something here
    }
});

链接到
$的API文档。每个
。您还可以放置一个