remy / bind.js

bind.js - simple two way data binding to HTML and callbacks
694 stars 62 forks source link

Recommendation: Add index to array transform #45

Closed shaack closed 3 years ago

shaack commented 3 years ago

I would recommend to add an index to the "transform" method of arrays like this: Line 272:

let index = 0
    forEach(value, function (value) {
    html.push(transform(value, target, index++));
});

then you can use the index in your mapping to know where a user has clicked in a list.

transform: (value, bind, index) => {
     return '<li><label><input data-index="' + index + '" type="checkbox" ' + (value.done ? " checked" : "") + '/>' + value.text + '</label></li>'
}
shaack commented 3 years ago

The more I think about the less important it is.