I have similar problem with this: Combine 3 functions into one in javascript
I have functions:
test: function() {
for (var i = 0; i < settings.columns.test.length; i++) {
$table.find('tbody td.test').each(function() {
$.each(jQuery.parseJSON(settings.columns.test[i][1]), function(index, value) {
if ($(this).text() === value) {
input += '<option value="' + index + '" selected>' + value + '</option>';
} else {
input += '<option value="' + index + '">' + value + '</option>';
}
//more code...
});
});
}
},
test2: function() {
for (var i = 0; i < settings.columns.test2.length; i++) {
$table.find('tbody td.test2').each(function() {
$.each(jQuery.parseJSON(settings.columns.test2[i][1]), function(index, value) {
if ($(this).text() === value) {
input += '<option value="' + index + '" selected>' + value + '</option>';
} else {
input += '<option value="' + index + '">' + value + '</option>';
}
//more code...
});
});
}
},
I'm calling these functions by:
columns: {
test1: [["key", '{"0": "First value", "1": "Second Value"}']],
test2: [["key", '{"0": "One more value", "1": "One more more value"}']]
}
As you see, these two functions are same, only test
-> test2
.. Is it possible to make one function and call it with another values for selector? Thanks in advance