javascript - How to assign variable to json object -
'i'm trying assign variable parent div json string of child table , can't seem javascript straight.
what i'd see, or variation of:
{"blocks":[{"id":"115",courses:[{"semester":"s,f","credits":"3","subject":"act"}, {"semester":"f","credits":"6","subject":"csi"}]}]
and jquery have far.
$('#update').click(function (e){ var table = $('#table').tabletojson(); var blockid = $('#table').closest('div.block').attr('id'); table = {"block":table}; document.getelementbyid('courselist').value = json.stringify(table); }
i'm not sure how add in variable need in object? how insert blockid?
i'm assuming bracket notation you're looking :
$('#update').on('click', function(){ var table = $('#table').tabletojson(); var blockid = $('#table').closest('div.block').attr('id'); var table2 = {}; table2[blockid] = table; $('#courselist').val( json.stringify(table2) ); });
Comments
Post a Comment