Can I use dynamic content in a Bootstrap popover?

前端 未结 5 1026
独厮守ぢ
独厮守ぢ 2020-12-29 07:44

I am using a Bootstrap Popover in a \'Repeat Region\' which displays Testimonials. Each testimonials has a \'View Property Details\' button which opens up the popover. In th

5条回答
  •  無奈伤痛
    2020-12-29 08:16

    my solution is based upon the previous solutions here, with a bit more. i needed (as usually), all the complexity: here's how you can create the popover content on demand when the event triggers, and have the selected element passed to the creating function.

    function displayProductPrice(a, tag) {
        var div = a.closest('div');
        var secs = ['aggregated', 'compare', 'list', 'saved', 'details'];
        var title = '';
        for (var c in secs) {
            var obj = $('.product-price-' + secs[c], div);
            if (obj.length) {
                if (title) {
                    title += '
    '; } title += obj.html(); } } return '<' + tag + '>' + title + ''; } $( document ).ready(function() { $(".product-price-expand").popover({ content: function() {return displayProductPrice(this, 'h6')}, title: function() { return $('.product-id', this.closest('div')).html(); }, html: true, trigger: 'click focus', placement: 'auto' }); });

    enjoy, hope this helps.

提交回复
热议问题