foreach 루프 내에서 사용하고 싶기 때문에 여러 동적 드롭 다운을 사용하려고합니다. 프로세스에서 아래에서 스크린 샷을 찍은 각 직책에 대한 단계와 상태가 있습니다. 직함을 반복하고 동적 드롭 다운을 배치했습니다. foreach 루프 내부의 단계 및 상태. 문제는 내가 스테이지를 선택하면 내가 선택한 스테이지에 따라 모든 상태가 계속 변한다는 것입니다. 예를 들어 위 사진 에서처럼 내가 "에서 스테이지를 선택하면 내가 스테이지를 선택한 상태에만 영향을 미치고 싶습니다." Chinese traslator (listening, speaking) "직책은 자신의 단계에있는 지위에만 영향을 주어야하며"캐셔 "직책에있는 지위에 영향을주지 않아야합니다.
지금까지 한 코드에 대한 코드는 다음과 같습니다.
<?php
$jobmatches = \App\Models\Jobposition::where('require_position',$jobseekers->desire_position_1)->orderBy('free_or_paid','desc')->pluck('id');
?>
@foreach($jobmatches as $value)
<?php $job_list = \App\Models\Jobposition::where('id',$value)->first(); ?>
<div class="form-group">
<input type="checkbox" name="job_position[]" value="{{ $job_list['id']}}">
{{ $job_list['job_title']}}<br>
</div>
<div class="form-group">
<label for="title">Select Stage:</label>
<select name="stage[]" class="form-control" >
<option value="">--- Select Stage ---</option>
@foreach ($stages as $key => $value)
<option value="{{ $key }}">{{ $value }}</option>
@endforeach
</select>
</div>
<div class="form-group">
<label for="title">Select Status:</label>
<select name="status[]" class="form-control">
</select>
</div>
@endforeach
여기에 아약스 코드가 있습니다.
$(document).ready(function() {
$('select[name="stage[]"]').on('change', function() {
var stateID = $(this).val();
if(stateID) {
$.ajax({
url: '/myform/ajax/'+stateID,
type: "GET",
dataType: "json",
success:function(data) {
$('select[name="status[]"]').empty();
$.each(data, function(key, value) {
$('select[name="status[]"]').append('<option value="'+ key +'">'+ value +'</option>');
});
}
});
}else{
$('select[name="status[]"]').empty();
}
});
});
어떤 도움이라도 대단히 감사하겠습니다.
interelated 요소 그룹에 래핑 div를 추가합니다.
<div class="job-list">
<div class="form-group">
<input type="checkbox" name="job_position[]" value="{{ $job_list['id']}}">
{{ $job_list['job_title']}}<br>
</div>
<div class="form-group">
<label for="title">Select Stage:</label>
<select name="stage[]" class="form-control" >
<option value="">--- Select Stage ---</option>
@foreach ($stages as $key => $value)
<option value="{{ $key }}">{{ $value }}</option>
@endforeach
</select>
</div>
<div class="form-group">
<label for="title">Select Status:</label>
<select name="status[]" class="form-control">
</select>
</div>
</div>
그런 다음 JS에서 동일한 그룹의 요소로만 작업하도록 핸들러를 조정할 수 있습니다.
$(document).ready(function() {
$('select[name="stage[]"]').on('change', function() {
var stateID = $(this).val();
/* define the target select, use closest to go back up to the job-list parent,
* then pull the select element that is a child of it
*/
var $select = $(this).closest('.job-list').find('select[name="status[]"]');
if(stateID) {
$.ajax({
url: '/myform/ajax/'+stateID,
type: "GET",
dataType: "json",
success:function(data) {
$select.empty();
$.each(data, function(key, value) {
$select.append('<option value="'+ key +'">'+ value +'</option>');
});
}
});
}else{
$select.empty();
}
});
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다