I have the following snippet:
var options = [];
$("tr.mks-option-row").each(function (row) {
options.push({
Id: $(row).data("option-id"),
CategoryId: $(row).data("category-id"),
Value: $(row).data("option-text")
});
});
Where .mks-option-row is the selector for all the rows in a table. The table contains several elements of data, which I have also repeated as data-attributes on the tr itself.
However, when this snippet is done, the options array contains n empty object literals. If there are 4 rows in the table the array contains [{},{},{},{}]
What am I doing wrong here? (I have also tried using quoted identifiers with no difference in outcome)
console.log(row, $(row)){ Id: undefined, CategoryId: undefined, Value: undefined }. Are you checking the output usingJSON.stringify? That might explain it. Please post how you are getting[{},{},{},{}], and also post an example HTML which lets us reconstruct your result.$.eachis$.each(index, element). Just rectify it.