0
lyricsInp = document.getElementById("lyrics").value;
var lines = lyricsInp.split("\n");
for (i = 0; i < lines.length; i++) {
    holder[0][i] = new Array();
    words = lines[i].replace(/[ \t\r]+/g, "###").split("###");
    for (j = 0; j < words.length; j++) {
        holder[0][i][j].word = words[j];
        holder[0][i][j].startT = 0;
        holder[0][i][j].endT = 0;
    }
}

在这里,我需要每个支架元素保留word, startTand endT,但这不起作用。我该如何做到这一点。

4

3 回答 3

1

声明holder[0][i][j]为对象字面量:

for (j = 0; j < words.length; j++) {
    holder[0][i][j] = {};

    holder[0][i][j].word = words[j];
    holder[0][i][j].startT = 0;
    holder[0][i][j].endT = 0;
}
于 2012-11-01T15:14:46.667 回答
0
lyricsInp =  document.getElementById("lyrics").value;
var lines = lyricsInp.split("\n");
for (i=0;i<lines.length;i++){
    holder[0][i] = new Array();
    words = lines[i].replace(/[ \t\r]+/g,"###").split("###");
    for (j=0;j<words.length;j++){
        holder[0][i][j] = {
                word: words[j],
                startT: 0,
                endT: 0
            };
    }
}
于 2012-11-01T15:15:06.577 回答
0
var holder = [[]];

var lyricsInp = document.getElementById("lyrics").value,
    lines = lyricsInp.split("\n");
for (var i = 0; i < lines.length; i++) {
    holder[0][i] = [];
    var words = lines[i].replace(/[ \t\r]+/g, "###").split("###");
    for (var j = 0; j < words.length; j++) {
        holder[0][i][j] = {
            word: words[j],
            startT: 0,
            endT: 0
        };
    }
}
于 2012-11-01T15:17:59.333 回答