2013-04-04 142 views
0

对于我正在处理的项目,有几个按钮可打开不同的模式弹出窗口。每个窗口都有自己的复选框。如何将变量存储到存储到另一个数组(jQuery)的数组中

用户选择某些复选框然后关闭模式后,复选框信息将存储在数组中并显示在页面上。

我的问题是,当用户重新打开相同的模式弹出窗口时,我需要填写这些相同的复选框。我发现了一个stackoverflow question which covers this here.

但是我的问题是,似乎我必须创建一个唯一的变量/数组,然后将该数组放入一个主数组,我不知道如何做到这一点。

// id of the button so I can use the name to open unique popups 
// and create unique variable names 
var roleId = ''; 

// The main Array to store all my button/checkbox lists Arrays into 
var storedArray = [];  

// The Array that stores the currently selected checkbox items. 
var selectedArray = []; 


// The function that is on all the buttons that bring up the checkbox modals 
$('.role').click(function(){ 

    // Saves a unique ID to be used to open up the appropriate popup 
    roleId = $(this).attr('tag'); 

    // Here I try to create a Variable for a unique Array 
    storedArray.push('stored'+roleName); 

    // Selects the appropriate Modal popup 
    $('#modal-'+roleId).modal(); 
    return false; 
}); 

// Later the function that saves the checkbox items that are selected: 
    $('input:checked').each(function() { 
     selectedArray.push($(this).val()); 
    }); 

// Where I try to store the checkbox data into the 
// storedArray which is inside the slected Array 
    storedArray.push(selectedArray); 
    console.log('2 storedArray = '+storedArray); 
+0

你使用的是什么模式库? – 2013-04-04 19:15:19

+0

简单模态http://www.ericmmartin.com/projects/simplemodal/ :) – 2013-04-04 19:16:42

回答

1

查看SimpleModal的文档,有一个persist选项。这是否做你想要的?

$('#modal-'+roleId).modal({persist:true}); 
+0

哦酷!也许,现在就试试这个...... – 2013-04-04 19:23:45

+0

就是这样!非常感谢:)甚至没有想到这种可能的功能 – 2013-04-04 19:42:44

相关问题