Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a JSON list?

I have to form a JSON object like

var SelectedRows=   {
        "item1":{"id":"1","name":"jhon","phone":"6699"},
        "item2":{"id":"2","name":"Aron","phone":"7799"},
        "item2":{"id":"3","name":"Iyan","phone":"8899"},
        }

On check box click event, I need to add the grid row values to the JSON list. I am trying with this code:

var SelectedRows={};

$(this).delegate(":checkbox", "click", function() {        
    var j=0;
    var item=[];
    SelectedRows[item]={};        *//I guess this line creating problem*     
    $(this).closest("tr").find("td:visible").each(function(){            
        var key=headerRow[j]["i"];            
        if(j == 0)
        {              
        }
        else
        {   
            SelectedRows[item][key]=$(this).text(); 
        }
        j=++j; 
     });

After multiple checkbox click events happening,SelectedRows contains only last click event data.

How get all the checkboxes click events data?

like image 612
User_MVC Avatar asked Oct 22 '22 20:10

User_MVC


1 Answers

You can create an json array like this

var SelectedRows=   [
    item1:{id:"1",name:"jhon",phone:"6699"},
    item2:{id:"2",name:"Aron",phone:"7799"},
    item2:{id:"3",name:"Iyan",phone:"8899"}
]
like image 196
Anshu Avatar answered Oct 24 '22 16:10

Anshu