I try to copy to clipboard some information from Knockout foreach:
<tbody data-bind="foreach: selections">
<tr>
<td>
<a href="#" class="copy_btn" data-bind="attr: { 'data-clipboard-text' : name}"><i class="fa fa-copy"></i></a>
</td>
</tr>
</tbody>
with ClipboardJS:
var btns = document.querySelectorAll('a.copy_btn');
var clipboard = new Clipboard(btns);
clipboard.on('success', function (e) {
console.log(e);
});
clipboard.on('error', function (e) {
console.log(e);
});
But it's not copying. What I'm doing wrong?
So, maybe somebody needs:
and
Alrighty, thanks @devspec for your initial answer. I built on it in some crucial ways:
so my final binding handler is:
And an example of usage is:
The Html:
on the view model command is a computed, if it was a function that returned a string (without an argument) you could use the text attribute only
And the copyCommandResult is simply: