admin管理员组文章数量:1403435
I currently have a dropdown that will display notifications
<li class="notifications dropdown">
<a class="dropdown-toggle" id="dLabel" role="button" data-remote="true" data-toggle="dropdown" data-target="#" href="/notifications"><i class="icon-user"></i> Notifications</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
</ul>
</li>
The ul dropdown is empty but on click of the link I want to populate the menu with data from rails.
I currently have this in notifications.js.erb
$(".nav li.notifications .dropdown-menu").remove();
$(".nav li.notifications").append("<%= escape_javascript(render('users/notifications', notifications: @notifications)) %>");
Normally I would set the dropdown link to remote but since I am using a bootstrap's dropdown no request is being sent to notifications.js.erb. How can I manually call the code there?
I currently have a dropdown that will display notifications
<li class="notifications dropdown">
<a class="dropdown-toggle" id="dLabel" role="button" data-remote="true" data-toggle="dropdown" data-target="#" href="/notifications"><i class="icon-user"></i> Notifications</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
</ul>
</li>
The ul dropdown is empty but on click of the link I want to populate the menu with data from rails.
I currently have this in notifications.js.erb
$(".nav li.notifications .dropdown-menu").remove();
$(".nav li.notifications").append("<%= escape_javascript(render('users/notifications', notifications: @notifications)) %>");
Normally I would set the dropdown link to remote but since I am using a bootstrap's dropdown no request is being sent to notifications.js.erb. How can I manually call the code there?
Share Improve this question asked Oct 14, 2012 at 18:35 Matthew HuiMatthew Hui 3,3712 gold badges31 silver badges38 bronze badges1 Answer
Reset to default 6I would add JavaScript code to make the call:
$(document).ready(function() {
$('#dLabel').click(function() {
// Only call notifications when opening the dropdown
if(!$(this).hasClass('open')) {
$.ajax({
type: "GET",
url: "/notifications",
async: false,
dataType: "script"
});
}
});
});
You could also make it asynchronous and put a loading icon into the menu temporarily...
本文标签: javascriptRails Populating bootstrap dropdown with ajaxStack Overflow
版权声明:本文标题:javascript - Rails: Populating bootstrap dropdown with ajax - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744417060a2605251.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论