我正在使用Yii2 php框架,这是我如何显示第一个下拉列表:
$deductions = PayrollItems::find()->where(['store_id' => $session['store_id']])->orwhere(['store_id' => null])->where(['payroll_type' => 'Deduction'])->all();
$deductionslistData = ArrayHelper::map($deductions,'payroll_items_id', 'payroll_name');
echo $form->field($model2, 'deduction_item_id')->widget(Select2::classname(), [
'data' => $deductionslistData,
'options' => ['placeholder' => 'Select a Deduction ', 'id' => 'deduction_item'],
'pluginOptions' => [
'allowClear' => true
],
]);
?>
以下是用于附加新下拉列表的脚本函数:
function addDeductionItem(){
var count = $('#count2').val();
if($('#deduction_item').val()=="" || $('#deduction_item_' + count).val()==""){
alert("Please fill in the earning item field first!");
}
else{
count++ ;
$('#count2').val(count);
$.ajax({
url: 'index.php?r=payslip/deductions',
dataType: 'json',
method: 'GET',
data: {},
success: function (data, textStatus, jqXHR) {
$("#deduction_item_" + count).append($("").html(""));
//$("#deduction_item_" + count).append($("").val('add item').html("Add New Item"));
for(i=0; i
{
$("#deduction_item_" + count).append($("").val(data[i][1]).html(data[i][0]));
}
},
error: function (jqXHR, textStatus, errorThrown) {
console.log('An error occured!');
alert('Error in ajax request');
}
});
var deduction = '
';deduction += '
';$("#deduction_items").append(deduction);
$("#deduction_items").on('click','.ibtnDel',function(){
$(this).closest('tr').remove();
});
$('#row_' + count + ' select').select2();
}
}
我有一个下拉列表,例如它有3个选项,然后我选择选项01.现在,当我添加一个新的下拉列表时(通过点击我的案例中的“添加扣除项目”按钮),选项01在附加的下拉列表中将被禁用.
整个想法是,当我在第一个下拉列表中选择一个选项时,现在应该在附加的下拉列表中禁用所选的选项,依此类推.
我通过互联网搜索了这个问题.我发现了一些,但他们只是不适合我,因为我的问题与我发现的问题不太相似.
我发现并尝试了这个小提琴:http://jsfiddle.net/rajan222000/yww8apn9/1/
但仍然不适合我.我注意到它有静态的下拉列表数.我试过var deductionID =’deduction_item_’count”;使它动态,但我不知道为什么它不起作用.
我真的需要你的帮助.