I have a JavaScript object that has this structure:
var spouse = {
s_name: { value: spouse_name, label: "Name" },
s_nric: { value: spouse_nric_passport, label: "NRIC/Passport" },
s_dob: { value: spouse_date_of_birth, label: "Date of Birth" },
s_occupation: { value: spouse_occupation, label: "Occupation" },
s_weight: { value: spouse_weight, label: "Weight" },
s_height: { value: spouse_height, label: "Height" }
};
I am currently iterating through it like this:
$.each(spouses, function(key, value) {
console.log(value);
$.each(value, function(int_key, int_value) {
console.log(int_key);
console.log(int_value.value);
console.log(int_value.label);
$("#spouse_data").append(
"<div class='col-sm-4'><label>" +
int_value.label +
"</label><input type='text' readonly class='form-control' value=" +
int_value.value +
"></div>"
);
});
});
What this does is place the elements into dynamically generated html elements. However, I am unsure of how I can place the remove function. At the moment if I place it within the loop, each row of data within a structure will contain a remove function instead of a general remove function.
How can I change this so that I can add a general remove function? Or is there a better way to print out this structure onto the screen?
a remove function instead of a general remove function??remove. While rendering the list, add a checkbox and set the current index as the its ID. This checkbox, whenever checked, will call the functionmarkForRemoval(markForRemovalbasically adds the ID to an array, which is later used byremovemethod.) Hope it makes sense!