【发布时间】:2015-08-07 05:46:00
【问题描述】:
我有一些divs,需要将每个div 的数据存储在一个数组中。所以我使用了一个二维数组以下列方式存储这些数据。
this.saveBoardAndNotes = function (board_id, board_name) {
var noteList = new Array(new Array());
var self = this;
var count = 0;
$(".optimal-sticky-notes-sticker-note").each(function(){
// Replace plain urls with links and improve html
var note = $(this);
var content = note.find(".textarea").html();
var properties = JSON.stringify(self.getProperties(note));
var noteID = note.attr("id");
noteList[count]['content'] = content;
noteList[count]['properties'] = properties;
noteList[count]['noteID'] = noteID;
count++;
});
但是当我尝试在数组中存储多个 div 时,我在 firebug 中遇到以下错误
TypeError: noteList[count] is undefined
我该如何解决这个问题。顺便问一下,有没有优化的方法?提前致谢。
【问题讨论】:
-
我从未见过用这种方式在 JavaScript 中创建二维数组。
-
你错过了
photos[a] = [];; )。
标签: javascript jquery arrays