I am using Gridster for webpage.The gridster widgets are <li> elements placed in <ul>.I generating these widgets with the help of json.
I am passing the values of json to add_widget function of gridster which dynamically generates the widgets(li elements) for me.
The gridster has a builtin function serialize which generates a json encoding the widgets present.
I have modified the seriazlize function to return an extra
key value pair which can capture the content of textarea on the widgets.
Following is the function which helps in getting the extra key value pair
function serialize() {
var s = gridster.serialize();
$('.gridster ul li').each((idx, el) => { // grab the grid elements
s[idx].images= $('.imagenames', el).val(); // extract content from textarea with class:imagenames
s[idx].title = $('.hoverinformation', el).val(); // extract content from textarea with class:hoverinformation
json_variable = JSON.stringify(s)
});
$('#log').val(json_variable);
}
In the above function I am getting that element with class gridster is selected inside that <ul> is selected and in that each <li> is selected.
But I was not understanding what is .each((idx, el) => { this part
Also what is idx and el and this line entirely s[idx].images= $('.imagenames', el).val();.
HTML:
<div class="gridster">
<!-- <li> from JSON are placed here -->
<ul>
</ul>
<button class="js-seralize btn btn-success mr-2"> Serialize </button>
<textarea class="textarea form-control" id="log"></textarea>
</div>
Fiddle representing the same