jquery - assign multiple value to javaScript array object -
i have coded jquery widget, list record title in table user can select of multiple records each record user need put value in text box.
now want built jquery or javascript array can push record each user click add , remove data if click remove against each button.
i want push "recordid" & "componentschememarks" javascript array selectedcomponentlist
var selectedcomponentlist = { componentindex: "", componentmark:"" }; $(document).ready(function () { //click on confirm component scheme $("#componentschemetable").on("click", ".k-grid-confirm", function () { var recordid = $(this).data("id"); var componentschememarks = $("#" + recordid + "_cm").val(); alert("recordid " + recordid + " componentschememarks " + componentschememarks); // $(this).hide(); $(this).siblings(".k-grid-input").hide(); $(this).siblings(".k-grid-cancel").hide(); $(this).siblings(".k-grid-remove").show(); //add data array// }); $("#componentschemetable").on("click", ".k-grid-remove", function () { $(this).hide(); $(this).siblings(".k-grid-add").show(); });
your selectedcomponentlist
not array... guess want this:
var selectedcomponentarray = []; $(document).ready(function () { //click on confirm component scheme $("#componentschemetable").on("click", ".k-grid-confirm", function () { var recordid = $(this).data("id"); var componentschememarks = $("#" + recordid + "_cm").val(); alert("recordid " + recordid + " componentschememarks " + componentschememarks); // $(this).hide(); $(this).siblings(".k-grid-input").hide(); $(this).siblings(".k-grid-cancel").hide(); $(this).siblings(".k-grid-remove").show(); //add data array// selectedcomponentarray.push({componentindex: recordid, componentmark: componentschememarks}); }); $("#componentschemetable").on("click", ".k-grid-remove", function () { $(this).hide(); $(this).siblings(".k-grid-add").show(); var recordid = $(this).data("id"); selectedcomponentarray = $.grep(selectedcomponentarray, function(value) { return value.componentindex != recordid; }); }); ... }
moreover should give buttons ids , use them binding click listeners...
Comments
Post a Comment