1

I wrote this code to scrape a sparse array from a series of dom elements. when done in one dimension the code works but in 2 dimensions it fails. Is there something i'm missing?

23         function initCellHover(){
24                 $cells.each(function(){
25                         var arrayX = $(this).position().left/cellWidth;
26                         var arrayY = $(this).position().top/cellHeight;
27                         var arrayValue = $(this);
28                         cellLookup[arrayX][arrayY] = arrayValue;
29                 });     
30         }  
4

1 回答 1

5

In line 28 you may be referring to a property of undefined. It makes sense to check, if there already is a property in the array and add it, if needed:

cellLookup[arrayX] = cellLookup[arrayX] || [];
cellLookup[arrayX][arrayY] = arrayValue;
于 2012-05-27T08:33:29.300 回答