for正在获取JavaScript中的最后一项
我有这个密码for正在获取JavaScript中的最后一项,javascript,php,laravel,for-loop,Javascript,Php,Laravel,For Loop,我有这个密码 <?php $json = json_encode($question->varz); ?> @section('script') <script type="text/javascript"> const nameSelect = $('<select></select>'); const person1 = $(' @foreach($question->answers as $answer)@if($answer
<?php $json = json_encode($question->varz); ?>
@section('script')
<script type="text/javascript">
const nameSelect = $('<select></select>');
const person1 = $(' @foreach($question->answers as $answer)@if($answer->drop_down_owner==0) <option value="person1"> {{$answer->text}}</option> @endif @endforeach');
nameSelect.append(person1);
const ageSelect = $('<select></select>');
const age1 = $(' @foreach($question->answers as $answer)@if($answer->drop_down_owner==1) <option value="person1"> {{$answer->text}}</option> @endif @endforeach');
ageSelect.append(age1);
var json = <?php echo $json; ?>;
const dropdown = [ nameSelect, ageSelect];
for (var i = 0; i < json.length; i++)
{
if(json[i] != "#KDPOPTION"){
$('#dropdowns').append(json[i]);
}else
{
$('#dropdowns').append($(dropdown[0]));
}
}
</script>
所以,如果我问伊恩,但是另一个帐户?是的,我知道我和一个朋友一起工作,她问了这个问题,她在5天内不能问,所以我在同一代码中问不同的问题,如果有人能帮助我,我将不胜感激。。
Iam[appears the dropdown]andIam[appears the dropdown]yearsold.