I need help with the following:
Iwanttogetthecheckboxthatisdisabledandplayonconsole0forwhatisdisabled,and1forwhatisenabled.
Mysourceislikethis:(asp.netmvc)
@modelIEnumerable<Apontamento.Models.Modulos>@{ViewBag.Title="Acesso";
Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
}
<h2>Acesso</h2>
<br />
<table class="table table-condensed table-striped">
<tr>
<th>
@Html.DisplayNameFor(model => model.cod_modulo)
</th>
<th>
@Html.DisplayNameFor(model => model.nome_modulo)
</th>
<th>
@Html.DisplayNameFor(model => model.usuario)
</th>
<th>
@Html.DisplayNameFor(model => model.permissao)
</th>
</tr>
@foreach (var item in Model)
{
<tr class="linha" data-codigo_modulo="@item.cod_modulo" data-usuario="@item.usuario">
<td>
@Html.DisplayFor(modelItem => item.cod_modulo)
</td>
<td>
@Html.DisplayFor(modelItem => item.nome_modulo)
</td>
<td>
@Html.DisplayFor(modelItem => item.usuario)
</td>
<td>
@Html.EditorFor(modelItem => item.permissao)
</td>
</tr>
}
</table>
<script type="text/javascript">
$(document).ready(function () {
$(".linha").each(function () {
var codigo_modulo = $(this).data("codigo_modulo");
var usuario = $(this).data("usuario");
var valor_atual = 0;
if ($(this).next("input").has("checked")) {
valor_atual = 1;
} else {
valor_atual = 0;
}
console.log(codigo_modulo + " " + usuario + " " + valor_atual);
});
});
</script>
I'm definitely in this jquery here:
<script type="text/javascript">
$(document).ready(function () {
$(".linha").each(function () {
var codigo_modulo = $(this).data("codigo_modulo");
var usuario = $(this).data("usuario");
var valor_atual = 0;
if ($(this).next("input").has("checked")) {
valor_atual = 1;
} else {
valor_atual = 0;
}
console.log(codigo_modulo + " " + usuario + " " + valor_atual);
});
});
</script>
I play console, but he plays like this (1 for everything)
Imadea$(".linha").each(function () {
to go through each line, the code of the module and the name is getting right, but this condition is not working:
var valor_atual = 0;
if ($(this).next("input").has("checked")) {
valor_atual = 1;
} else {
valor_atual = 0;
}
Can anyone help me with how to test whether the checkbox in the row is checked or not?
If it helps, the page source looks like this: (in the table) (notice that the second input is not with checked="checked"
<table class="table table-condensed table-striped">
<tr>
<th>
Código Modulo
</th>
<th>
Nome do Módulo
</th>
<th>
usuario
</th>
<th>
permissao
</th>
</tr>
<tr class="linha" data-codigo_modulo="1" data-usuario="dayane.fiedler">
<td>
1
</td>
<td>
Produtos
</td>
<td>
dayane.fiedler
</td>
<td>
<input checked="checked" class="check-box" data-val="true" data-val-required="O campo permissao é obrigatório." id="item_permissao" name="item.permissao" type="checkbox" value="true" /><input name="item.permissao" type="hidden" value="false" />
</td>
</tr>
<tr class="linha" data-codigo_modulo="2" data-usuario="dayane.fiedler">
<td>
2
</td>
<td>
Usuários
</td>
<td>
dayane.fiedler
</td>
<td>
<input class="check-box" data-val="true" data-val-required="O campo permissao é obrigatório." id="item_permissao" name="item.permissao" type="checkbox" value="true" /><input name="item.permissao" type="hidden" value="false" />
</td>
</tr>
<tr class="linha" data-codigo_modulo="3" data-usuario="dayane.fiedler">
<td>
3
</td>
<td>
Ordem Produção
</td>
<td>
dayane.fiedler
</td>
<td>
<input checked="checked" class="check-box" data-val="true" data-val-required="O campo permissao é obrigatório." id="item_permissao" name="item.permissao" type="checkbox" value="true" /><input name="item.permissao" type="hidden" value="false" />
</td>
</tr>
<tr class="linha" data-codigo_modulo="5" data-usuario="dayane.fiedler">
<td>
5
</td>
<td>
Adminstrador
</td>
<td>
dayane.fiedler
</td>
<td>
<input checked="checked" class="check-box" data-val="true" data-val-required="O campo permissao é obrigatório." id="item_permissao" name="item.permissao" type="checkbox" value="true" /><input name="item.permissao" type="hidden" value="false" />
</td>
</tr>
<tr class="linha" data-codigo_modulo="6" data-usuario="dayane.fiedler">
<td>
6
</td>
<td>
Operações
</td>
<td>
dayane.fiedler
</td>
<td>
<input checked="checked" class="check-box" data-val="true" data-val-required="O campo permissao é obrigatório." id="item_permissao" name="item.permissao" type="checkbox" value="true" /><input name="item.permissao" type="hidden" value="false" />
</td>
</tr>
</table>