Skip to content

Instantly share code, notes, and snippets.

@ewilazarus
Created July 9, 2015 17:17
Show Gist options
  • Save ewilazarus/ac07a712eba9c2cc50e1 to your computer and use it in GitHub Desktop.
Save ewilazarus/ac07a712eba9c2cc50e1 to your computer and use it in GitHub Desktop.
// BUG
var id = 1;
for (var i = 0; i < products.length; i++) {
if (contains(offsetX, offsetY, products[i], 4)) {
var productName = products[i].name
var button = $('<button></button>').
prop("class", "btn btn-xs btn-danger").
click(function() {
clean(id, productName);
}).
text("X");
var span = $('<span></span>').
addClass("pull-right").
append(button);
var li = $('<li></li>').
prop("id", "info" + id).
prop("class", "list-group-item clearfix").
text(productName).
append(span);
$("#info").append(li);
id++;
}
}
// CORRECAO
var id = 1;
for (var i = 0; i < products.length; i++) {
if (contains(offsetX, offsetY, products[i], 4)) {
var productName = products[i].name
var button = $('<button></button>').
prop("class", "btn btn-xs btn-danger").
click((function(id) {
return function() {
clean(id, productName);
}
})(id)).
text("X");
var span = $('<span></span>').
addClass("pull-right").
append(button);
var li = $('<li></li>').
prop("id", "info" + id).
prop("class", "list-group-item clearfix").
text(productName).
append(span);
$("#info").append(li);
id++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment