问题
I'm currently working in the 0.5 version of Siwapp and I'm trying to show a popover for the payments button on each row of a invoices table. But I have to do it with a click. I have the following JS code:
jQuery(function($){
$('table[data-type="invoices"] a.payments').popover({
live: true,
placement: 'left',
offset: 5,
html: true,
content: function() {
return $(this).attr('class');
},
trigger: 'manual'
}).live('click', function(e){
e.preventDefault();
$(this).popover('show');
});
});
The table HTML is like this (see the link at the end):
<table class="zebra-striped align-middle" data-type="invoices">
<colgroup>
<col />
<col />
<col class="date" />
<col class="date" />
<col class="status" />
<col class="currency" />
<col class="currency" />
<col class="payments" />
</colgroup>
<thead>
<tr>
<th>{% trans %}Number{% endtrans %}</th>
<th>{% trans %}Customer{% endtrans %}</th>
<th>{% trans %}Date{% endtrans %}</th>
<th>{% trans %}Due Date{% endtrans %}</th>
<th>{% trans %}Status{% endtrans %}</th>
<th>{% trans %}Due{% endtrans %}</th>
<th>{% trans %}Total{% endtrans %}</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>ASET-22</td>
<td>Roxxon</td>
<td>5/28/11</td>
<td>9/16/11</td>
<td>
<span class="label important">{% trans %}overdue{% endtrans %}</span>
</td>
<td></td>
<td>$11,435.23</td>
<td>
<a href="{{ path('invoice_payments', { 'invoiceId': 4 }) }}" class="btn secondary icon clock payments" title="Payments">{% trans %}Payments{% endtrans %}</a>
</td>
</tr>
</tbody>
</table>
If I remove the "manual" trigger it works but if I set it, it doesn't.
Anyone knows how to do this? Thanks!
回答1:
Popover will handle automaticaly some of what you're doing manually, and it's probably causing some weird conflicts. You're adding your own click handler unnecessarily when it can do that itself, and you're wrapping the whole setup function which doesn't seem necessary. Try something like this:
$('table[data-type="invoices"] a.payments').popover({
live: true,
placement: 'left',
offset: 5,
html: true,
content: function() {
return $(this).attr('class');
},
trigger: 'manual'
});
回答2:
Just an update: Bootstrap 2.1 lets you provide click
as a trigger. (http://twitter.github.com/bootstrap/javascript.html#popovers)
来源:https://stackoverflow.com/questions/7881092/how-to-show-popover-on-click