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 回答