【发布时间】:2021-08-12 09:49:12
【问题描述】:
我有一个如下所示的表格。 我有三个“白色”下拉列表来过滤设备注册标签下拉列表的值(具有设备注册标签标签的下拉输入字段的值只有在用户选择三个“白色”下拉列表的值后才会出现)。因此,设备注册标签值将根据“白色”下拉列表值而有所不同。
我希望它是一个实时过滤器,每次用户选择“白色”下拉值时,下拉选项都会立即更改。目前,我的方法是在“白色”下拉列表中使用onchange=" this.form.submit()" 属性并在过滤后返回值,但我意识到这种方法有一个缺点,即用户在更改“白色”的值时可能会不小心提交表单“下拉菜单。如何防止这种情况,只允许用户通过单击保存按钮提交表单?
$this->Calibration_Location = $request->get('selected_location');
$this->Calibration_Category = $request->get('selected_category');
$this->categories = Equipment::select('Category')->distinct()->get()->toArray();
$this->locations = Equipment::select('Location')->distinct()->get()->toArray();
$matchThese = ['Category' => $this->Calibration_Category, 'Location' => $this->Calibration_Location];
$this->Registration_Select_Tags = Equipment::select('Registration Tag')->distinct()->where($matchThese)->get();
我也试过jQuery,但只能通过指定的下拉字段触发,不能触发。
<script type="text/javascript">
$(document).ready(function() {
var location, category
$('#selected_transfer_location').change(function() {
location = $(this).val();
console.log(location);
$('#selected_transfer_category').change(function() {
category = $(this).val();
console.log(category);
});
// $('#transfer_registration_tag').find('option').not(':first').remove();
$.ajax({
url: 'Transaction/' + location + '/' + category,
type: 'get',
dataType: 'json',
success: function(response) {
var len = 0;
if (response.data != null) {
len = response.data.length;
}
if (len > 0) {
for (var i = 0; i < len; i++) {
var id = response.data[i]['Registration Tag'];
var name = response.data[i]['Registration Tag'];
var option = "<option value='" + id + "'>" + name +
"</option>";
$("#transfer_registration_tag").append(option);
}
}
}
})
});
});
</script>
我希望我的问题很清楚,对 Laravel 来说还是个新手,希望能从你那里得到一些提示。
【问题讨论】:
标签: php jquery laravel filter laravel-blade