2
I have a dropdownmenu that works normally when I load it using Asp.net core + Razor. Inside it I have the submenus Phones and WEB... When I try to recreate the submenus due to an app need, their items are positioned outside the submenu, unlike when it is loaded using the Asp.net Razor (Watch the phones).
Right should be right:
JS script that reloads submenus (I commented the part that loads the WEB submenu items):
function load_elements_dropdowns() {
//Carregar Listas
var selectAdicionarFormaContato = $('#btn-add-contato');
$.ajax({
url: "/pessoa-gerenciar/getFormaContatoList",
type: "POST",
data: { pessoaNatureza: $('#pessoaNatureza').val() },
traditional: true,
success: function (data) {
selectAdicionarFormaContato.empty();
selectAdicionarFormaContato.append($('<div class="dropdown-submenu"><a class="dropdown-item" href="javascript:void(0)" tabindex="-1">Telefones</a><div class="dropdown-menu" role="menu">'));
$.each(data, function () {
$.each(this, function (i, item) {
switch (item.id) {
case 1:
selectAdicionarFormaContato.append($('<a class="dropdown-item" href="javascript:void(0)" role="menuitem" tabindex="-1" data-id="' + item.id + '"><i class="icon fa-tty" aria-hidden="true"></i>' + item.descricao + '</a>'));
break;
case 2:
selectAdicionarFormaContato.append($('<a class="dropdown-item" href="javascript:void(0)" role="menuitem" tabindex="-1" data-id="' + item.id + '"><i class="icon wb-mobile" aria-hidden="true"></i>' + item.descricao + '</a>'));
break;
case 3:
selectAdicionarFormaContato.append($('<a class="dropdown-item" href="javascript:void(0)" role="menuitem" tabindex="-1" data-id="' + item.id + '"><i class="icon wb-print" aria-hidden="true"></i>' + item.descricao + '</a>'));
break;
case 4:
selectAdicionarFormaContato.append($('<a class="dropdown-item" href="javascript:void(0)" role="menuitem" tabindex="-1" data-id="' + item.id + '"><i class="icon md-headset-mic" aria-hidden="true"></i>' + item.descricao + '</a>'));
break;
}
});
});
selectAdicionarFormaContato.append($('</div></div><div class="dropdown-divider"></div>'));
selectAdicionarFormaContato.append($('<div class="dropdown-submenu"><a class="dropdown-item" href="javascript:void(0)" tabindex="-1">WEB</a><div class="dropdown-menu" role="menu">'));
//$.each(data, function () {
// $.each(this, function (i, item) {
// //select.append($('1'));
// switch (item.id) {
// case '5':
// console.log('Oranges are $0.59 a pound.');
// break;
// case '6':
// break;
// case '7':
// break;
// }
// });
//});
selectAdicionarFormaContato.append($('</div></div>'));
},
error: function () {
alert("Oops! Algo deu errado.");
}
});
}
Dropdownmenu complete code on Asp.net core
<div class="dropdown">
<button type="button" class="btn btn-primary dropdown-toggle"
aria-expanded="true" data-toggle="dropdown">
<i class="icon wb-plus" aria-hidden="true"></i>
Novo Contato
</button>
<div class="dropdown-menu" aria-labelledby="exampleDefaultDropdownSubMenu" role="menu" id="btn-add-contato">
<div class="dropdown-submenu">
<a class="dropdown-item" href="javascript:void(0)" tabindex="-1">Telefones</a>
<div class="dropdown-menu" role="menu">
@if (Model.FormasContato != null)
{
@foreach (var item in Model.FormasContato)
{
switch (item.Value)
{
case "1":
<a class="dropdown-item" href="javascript:void(0)" role="menuitem" tabindex="-1" data-id="@item.Value"><i class="icon fa-tty" aria-hidden="true"></i>@item.Text</a>
break;
case "2":
<a class="dropdown-item" href="javascript:void(0)" role="menuitem" tabindex="-1" data-id="@item.Value"><i class="icon wb-mobile" aria-hidden="true"></i>@item.Text</a>
break;
case "3":
<a class="dropdown-item" href="javascript:void(0)" role="menuitem" tabindex="-1" data-id="@item.Value"><i class="icon wb-print" aria-hidden="true"></i>@item.Text</a>
break;
case "4":
<a class="dropdown-item" href="javascript:void(0)" role="menuitem" tabindex="-1" data-id="@item.Value"><i class="icon md-headset-mic" aria-hidden="true"></i>@item.Text</a>
break;
}
}
}
</div>
</div>
<div class="dropdown-divider"></div>
<div class="dropdown-submenu">
<a class="dropdown-item" href="javascript:void(0)" tabindex="-1">WEB</a>
<div class="dropdown-menu" role="menu">
@if (Model.FormasContato != null)
{
@foreach (var item in Model.FormasContato)
{
switch (item.Value)
{
case "5":
<a class="dropdown-item" href="javascript:void(0)" role="menuitem" tabindex="-1" data-id="@item.Value"><i class="icon wb-envelope" aria-hidden="true"></i>@item.Text</a>
break;
case "6":
<a class="dropdown-item" href="javascript:void(0)" role="menuitem" tabindex="-1" data-id="@item.Value"><i class="icon glyphicon glyphicon-globe" aria-hidden="true"></i>@item.Text</a>
break;
case "7":
<a class="dropdown-item" href="javascript:void(0)" role="menuitem" tabindex="-1" data-id="@item.Value"><i class="icon fa-users" aria-hidden="true"></i>@item.Text</a>
break;
}
}
}
</div>
</div>
</div>
</div>
How to solve this problem? Where am I wrong? A hug to all!
Thank you so much for the great explanation @Sam!!! :)
– Master JR