简体   繁体   English

在动态元素上使用相同的tooltipster-tooltip获取动态内容

[英]Using same tooltipster-tooltip on dynamic elements for dynamic contents

I really like tooltipster, but I have a question now: I will generate a dynamic list of items and on each item should be a tooltip. 我非常喜欢工具提示,但是现在有一个问题:我将生成一个动态的项目列表,并且在每个项目上都应该有一个工具提示。 The content of this tooltip should be dynamic with an ID, which I send through tooltip to the page inside the tooltip. 该工具提示的内容应该是动态的,带有ID,我通过工具提示将其发送到工具提示中的页面。 But for sure, with my current code, I just get the dynamic content in every tooltip from the LAST ID of the list. 但是可以肯定的是,使用当前代码,我只能从列表的LAST ID中获得每个工具提示中的动态内容。 So, I don't know, how to use tooltipster and send for every list item the correct ID for the dynamic content in the tip. 因此,我不知道如何使用工具提示,并为每个列表项发送提示中动态内容的正确ID。

Here are my codes: 这是我的代码:

PHP of the list item(s): 清单项目的PHP:

<script type="text/javascript">
<?php
$NoteRelativeNoteIDphpVar = $FMID;
echo "var NoteRelativeNoteIDphpVariable = 'FMRelativeID={$NoteRelativeNoteIDphpVar}';";
?>
</script>
<div id="relative<?=$RID?>" class="relativeitem">
<div id="relativeitemrelative"><?=$FMRELATIVE?></div>
<div id="relativeitemname"><?=$FMNAME?></div>
<div id="relativeitemnote"><div id="iconnamenoterelative" class="FMRelativeNote" title="LoadRelativeNote"><img src="img/icon-note.png" class="iconnamenoterelativeimg" /></div></div>
<div id="relativeitemedit"><div id="iconeditrelative" style="background-color:<?=$CATCOL?>;"><a href="forms/Achgrelative.php?aid=<?=$RID?>" title="EDIT RELATIVE OF '<?=strtoupper($ANAME)?>'" class="box"><img src="img/icon-edit.png" class="iconrelativeimg" /></a></div></div>
</div>

Generated Example-HTML of the list item(s): 生成的列表项的示例HTML:

<script type="text/javascript">
var NoteRelativeNoteIDphpVariable = 'FMRelativeID=23';</script>
<div id="relative1" class="relativeitem">
<div id="relativeitemrelative">Father</div>
<div id="relativeitemname">Louis</div>
<div id="relativeitemnote"><div id="iconnamenoterelative" class="FMRelativeNote" title="LoadRelativeNote"><img src="img/icon-note.png" class="iconnamenoterelativeimg" /></div></div>
<div id="relativeitemedit"><div id="iconeditrelative" style="background-color:#247ac2;"><a href="forms/Achgrelative.php?aid=1" title="EDIT RELATIVE OF 'POLLY'" class="box"><img src="img/icon-edit.png" class="iconrelativeimg" /></a></div></div>
</div>
<script type="text/javascript">
var NoteRelativeNoteIDphpVariable = 'FMRelativeID=21';</script>
<div id="relative2" class="relativeitem">
<div id="relativeitemrelative">Sister</div>
<div id="relativeitemname">Twinny</div>
<div id="relativeitemnote"><div id="iconnamenoterelative" class="FMRelativeNote" title="LoadRelativeNote"><img src="img/icon-note.png" class="iconnamenoterelativeimg" /></div></div>
<div id="relativeitemedit"><div id="iconeditrelative" style="background-color:#247ac2;"><a href="forms/Achgrelative.php?aid=2" title="EDIT RELATIVE OF 'POLLY'" class="box"><img src="img/icon-edit.png" class="iconrelativeimg" /></a></div></div>
</div>

JS of used tooltipster: 二手工具提示的JS:

$(document).ready(function() {
    $('.FMRelativeNote').tooltipster({
        theme: 'tooltipster-shadow',
        position: 'right',
        contentAsHTML: true,
        onlyOne: true,
        interactive: true,
        functionInit: function(origin, content) {

            if (content === 'LoadRelativeNote') {
                //alert(RelativeNoteID);
                // when the request has finished loading, we will change the tooltip's content
                $.ajax({
                    type: 'POST',
                    url: 'inc/FMRelativeInfo.php',
                    data: NoteRelativeNoteIDphpVariable,
                    success: function(data) {
                        origin.tooltipster('content', data);
                    }
                });

                // this returned string will overwrite the content of the tooltip for the time being
                return 'Wait while the content is loading...';
            }
            else {
                // return nothing : the initialization continues normally with its content unchanged.
            }
        }
    });
});

So, I just need help please, to find the way to send always the correct ID from the PHP-list item to the tooltipster and not the LAST ID. 因此,我只需要帮助,以找到始终将正确的ID从PHP列表项发送到工具提示而不是LAST ID的方法。

PS: You can see in the screenshots-image, that the content is always the LAST content of the list, not the different one! PS:您可以在屏幕快照图像中看到,内容始终是列表的最后内容,而不是其他内容!

在此处输入图片说明

with a little help by the support of tooltipster, I found the solution on my own: 在tooltipster支持的帮助下,我自己找到了解决方案:

PHP: PHP:

<div id="iconnamenoterelative" class="FMRelativeNote" title="<?=$FMID?>">

HTML: HTML:

<div id="relative1" class="relativeitem">
<div id="relativeitemrelative">Father</div>
<div id="relativeitemname">Louis</div>
<div id="relativeitemnote"><div id="iconnamenoterelative" class="FMRelativeNote" title="23"><img src="img/icon-note.png" class="iconnamenoterelativeimg" /></div></div>
<div id="relativeitemedit"><div id="iconeditrelative" style="background-color:#247ac2;"><a href="forms/Achgrelative.php?aid=1" title="EDIT RELATIVE OF 'POLLY'" class="box"><img src="img/icon-edit.png" class="iconrelativeimg" /></a></div></div>
</div>
<div id="relative2" class="relativeitem">
<div id="relativeitemrelative">Sister</div>
<div id="relativeitemname">Twinny</div>
<div id="relativeitemnote"><div id="iconnamenoterelative" class="FMRelativeNote" title="21"><img src="img/icon-note.png" class="iconnamenoterelativeimg" /></div></div>
<div id="relativeitemedit"><div id="iconeditrelative" style="background-color:#247ac2;"><a href="forms/Achgrelative.php?aid=2" title="EDIT RELATIVE OF 'POLLY'" class="box"><img src="img/icon-edit.png" class="iconrelativeimg" /></a></div></div>
</div>

JS: JS:

$(document).ready(function() {
    $('.FMRelativeNote').tooltipster({
        theme: 'tooltipster-shadow',
        position: 'right',
        contentAsHTML: true,
        onlyOne: true,
        interactive: true,
        functionInit: function(origin, content) {

            if (content != '') {
                //alert(RelativeNoteID);
                // when the request has finished loading, we will change the tooltip's content
                $.ajax({
                    type: 'POST',
                    url: 'inc/FMRelativeInfo.php',
                    data: "FMRelativeID=" + content,
                    success: function(data) {
                        origin.tooltipster('content', data);
                    }
                });

                // this returned string will overwrite the content of the  tooltip for the time being
                return 'Wait while the content is loading...';
            }
            else {
                // return nothing : the initialization continues normally with its content unchanged.
            }
        }
    });
});

THANK YOU and maybe it helps somebody too! 谢谢,也许它也对某人有帮助! :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM