Javascript 如何根据表单中以前选中的复选框获取无线电复选框列表?
基于此表单上一页的复选框,我无法在表单中获取有限的无线电复选框列表。存在M2M类别组织的关系。因此,通过检查几个类别,我可以得到这些类别所属的所有组织的列表。无线电复选框列表是用ajax加载的。我知道我应该通过复选框的值进行过滤,但我不知道如何进行过滤。下面html中的注释代码显示了它的外观。首先是静态的Javascript 如何根据表单中以前选中的复选框获取无线电复选框列表?,javascript,html,jquery,forms,django-rest-framework,Javascript,Html,Jquery,Forms,Django Rest Framework,基于此表单上一页的复选框,我无法在表单中获取有限的无线电复选框列表。存在M2M类别组织的关系。因此,通过检查几个类别,我可以得到这些类别所属的所有组织的列表。无线电复选框列表是用ajax加载的。我知道我应该通过复选框的值进行过滤,但我不知道如何进行过滤。下面html中的注释代码显示了它的外观。首先是静态的 here is the part with checkboxes: <div class="form--steps-container"> &l
here is the part with checkboxes:
<div class="form--steps-container">
<div class="form--steps-counter">Krok <span>1</span>/5</div>
<form action="form-confirmation.html" method="post">
{% csrf_token %}
<!-- STEP 1: class .active is switching steps -->
<div data-step="1" class="active">
<h3>Zaznacz co chcesz oddać:</h3>
{% for category in categories %}
<div class="form-group form-group--checkbox">
<label>
<input
type="checkbox"
name="categories"
class = "checkbox"
value={{ category.id }}
/>
<span class="checkbox"></span>
<span class="description" id = "opis"
>{{ category.name}}</span
>
</label>
</div>
{% endfor %}
here is the part with radio checkboxes loaded with ajax:
<!-- STEP 4 -->
<div data-step="3" id = 'steps'>
<h3>Wybierz organizacje, której chcesz pomóc:</h3>
<!--
<div class="form-group form-group--checkbox">
<label>
<input type="radio" name="organization" value="old" />
<span class="checkbox radio"></span>
<span class="description" id = "span">
<div class="title" id ="name">Fundacja “Bez domu”</div>
<div class="subtitle" id = "description">
Cel i misja: Pomoc dla osób nie posiadających miejsca
zamieszkania
</div>
</span>
</label>enter code here
</div>
<div class="form-group form-group--checkbox" id = "changelist-form">
<label>
<input type="radio" name="organization" value="old" />
<span class="checkbox radio"></span>
<span class="description">
<div class="title">Fundacja “Dla dzieci"</div>
<div class="subtitle">
Cel i misja: Pomoc osobom znajdującym się w trudnej sytuacji
życiowej.
</div>
</span>
</label>
</div>
-->
<div class="form-group form-group--buttons" id = "guzik">
<button type="button" class="btn prev-step">Wstecz</button>
<button type="button" class="btn next-step">Dalej</button>
</div>
</div>
app.js - here with ajax I have loaded a list of all organizations, which should be filtered by value of checked checkboxes. However I tried several times and can't get the expected result
$(document).ready(function()
{
$.ajax({
url:"http://127.0.0.1:8000/institution/",
dataType: "json",
success: function(data)
{
for (let i =0; i<data.length; i++)
{
console.log(data[i].categories)
//var check = data[i].categories
//for (let i=0; i<check.length; i++){
//console.log(check[i])
//}
//if(check[i] == )
//console.log("stop")
//console.log(data[i].categories)
//console.log(check[1])
//console.log(data[i].categories.length)
var rows = $('<div class="form-group form-group--checkbox">\n' +
' <label>\n' +
' <input type="radio" name="organization" value="old" />\n' +
' <span class="checkbox radio"></span>\n' +
' <span class="description" id = "span">\n' +
' <div class="title" id ="name">' + data[i].name + '</div>\n' +
' <div class="subtitle" id = "description">' + data[i].description + '</div>\n' +
' </label>\n' + ' </span>\n' +
' </div>');
$(rows).insertBefore("#guzik");
}
}
});
});
以下是带有复选框的零件:
克朗1/5
{%csrf_令牌%}
扎兹纳茨公司chcesz oddać:
{categories%%中的类别为%s}
{{category.name}
{%endfor%}
以下是使用ajax加载的无线电复选框的部分:
Wybierz组织,której chcesz pomóc:
Wstecz
达莱杰
js-在这里,我使用ajax加载了所有组织的列表,应该通过复选框的值进行过滤。但是我试了好几次,都没有达到预期的效果
$(文档).ready(函数()
{
$.ajax({
url:“http://127.0.0.1:8000/institution/",
数据类型:“json”,
成功:功能(数据)
{
对于(让i=0;我可以显示json输出吗?此外,您只需要根据json值选中复选框?您可以显示json输出吗?此外,您只需要根据json值选中复选框?