1

最終的には「Title 1E」になるかもしれません。これは、以下の対応する配列を作成する必要が["Title 1E", '8']ある (私はやりたくない) か、すべての潜在的なタイトル 1 のプレースホルダーを作成する (つまり["Title 2A", '100']、空白のタイトル 1 の 4-99 に変更して作成する) 必要があるため、問題を引き起こします。空白行でいっぱいの非常に長いメニューを作成します。

適切な配列を手動で挿入しますsubsubmenu

動作する場合submenu[0].push(4,1," "Title 1E", '4' ")、次を次のように変更するにはどうすればよいですか["Title 2A", '5']

意味があることを願っています。私の頭の中ですべてがはっきりしているわけではありません。

(function() {
var submenu= [
        [   ["Title 1A", '0'],
            ["Title 1B", '1'],
            ["Title 1C", '2'],
            ["Title 1D", '3']
        ],

        [       ["Title 2A", '4'],
            ["Title 2B", '5'],
            ["Title 2C", '6'], 
            ["Title 2D", '7']  
        ],


];

//the Array below populates a sub-submenu when a selection is made above


var subsubmenu= [           

[   ["Issue 1A1", 'resonse1a1'],
        ["Issue 1A2", 'response1a2'],
        ["Issue 1A3", 'response1a3'],
        ["Issue 1A4", 'response1a4']
    ],

    [   ["Issue 1B1", 'resonse1b1'],
        ["Issue 1B2", 'resonse1b2'], 
        ["Issue 1B3", 'resonse1b3']
    ],


    [   ["Issue 1C1", 'resonse1c1']
    ],
        // etc...               
        ];
4

1 に答える 1

0

残りのアイテムを手動でループし、カウンターを手動で増やす必要があります。このような

var submenu= [
        [   ["Title 1A", '0'],
            ["Title 1B", '1'],
            ["Title 1C", '2'],
            ["Title 1D", '3']
        ],

        [       ["Title 2A", '4'],
            ["Title 2B", '5'],
            ["Title 2C", '6'], 
            ["Title 2D", '7']  
        ],
];

var insert_at=0;
submenu[insert_at].push(["Title 1E", '4']);

// Since the item will be pushed at the last position in the corresponding array
// We need to increase the counter i.e. item at position 1 for all the following 
//items in the other arrays
for(i=insert_at+1;i<submenu.length;i++){
    for(j=0;j<submenu[i].length;j++){
        submenu[i][j][1]++;
    }
}

// Now display that to confirm that it works ok
for(i=insert_at+1;i<submenu.length;i++){
    for(j=0;j<submenu[i].length;j++){
        document.write(submenu[i][j]);
    }
}

http://jsfiddle.net/gunjankarun/zCjY5/でチェックしてください

于 2013-03-13T05:36:54.647 に答える