jQuery qTip2 中的 Rails 动态内容
我的 jQuery qTip2 可以正常工作,但我还有最后一件事要解决:获取动态内容以链接形式显示在工具提示中。 (我对这一切都很陌生,所以请耐心等待。)
这是我现在要显示的 qTip:
$(document).ready(function() {
$('span[title]').qtip({
position: {
my: 'bottom center',
at: 'top center'
},
hide: {
fixed: true
},
style: {
classes:'ui-tooltip-shadow ui-tooltip-rounded'
}
});
});
这是我的 erb 文件:
<li class="article"><span title="<%= author.name %>">
<%= article.body %>,
</span></li>
呈现的 HTML:
<li class="article"><span title="My Name">
Testing,
</span></li>
不过,我想要做的是显示一个链接作为 qTip显示作者的姓名及其个人资料的链接。我知道我可以在 application.js 文件中添加一个链接,如下所示:
**content: {
text: '<a href="link">My name</a>'},**
但是,如何才能使内容从我的数据库动态添加?理想情况下,我想要类似的内容:
**content: {
text: '<a href="`<%= article.author.profile %>`">`<%= author.name %>`</a>'},**
我从之前的答案中知道生成有效 HTML 存在问题。不过我希望有人能在这里帮助我。
I got my jQuery qTip2 working but I have one last thing to solve: getting dynamic content to display as a link in the tooltip. (I'm new to all this so please bear with me.)
Here's what I have now to get the qTip to show:
$(document).ready(function() {
$('span[title]').qtip({
position: {
my: 'bottom center',
at: 'top center'
},
hide: {
fixed: true
},
style: {
classes:'ui-tooltip-shadow ui-tooltip-rounded'
}
});
});
Here's my erb file:
<li class="article"><span title="<%= author.name %>">
<%= article.body %>,
</span></li>
The HTML rendered:
<li class="article"><span title="My Name">
Testing,
</span></li>
What I want to do though is display a link as the qTip that shows the author's name and links to their profile. I know I can add a link in my application.js file like so:
**content: {
text: '<a href="link">My name</a>'},**
However, how can I make it so the content adds dynamically from my database? Ideally I'd want something like:
**content: {
text: '<a href="`<%= article.author.profile %>`">`<%= author.name %>`</a>'},**
I know from a previous answer that there is an issue with producing valid HTML. However I'm hoping someone can help me out here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实现此目的的一种方法是对服务器进行 ajax 调用,以根据内容获取要在工具提示中显示的动态 HTML。您可以使用
onRender
的api
方法来完成此操作:编辑:
您可以在 qtip2 中使用 ajax 方法:
看一下 ajax 链接查看从服务器获取数据的其他方法,但上面的示例如果你恢复基本的 HTML 就可以了。
One way you can accomplish this is to do an ajax call to the server to get the dynamic HTML you want to display in the tooltip depending on the content. You can use the
api
method ofonRender
to accomplish this:EDIT:
You can do the same thing in qtip2 by using the ajax method:
Take a look at the ajax link to see the other ways to get data from the sever, but the example above will work if you are getting back basic HTML.