Laravel-admin 解决表单 select 联动时,编辑默认没选上
/vendor/encore/laravel-admin/src/Form/Field
下的Select.php
文件
$script = <<<EOT
$(document).off('change', "{$this->getElementClassSelector()}");
$(document).on('change', "{$this->getElementClassSelector()}", function () {
var target = $(this).closest('.fields-group').find(".$class");
$.get("$sourceUrl",{q : this.value}, function (data) {
target.find("option").remove();
$(target).select2({
placeholder: $placeholder,
allowClear: $allowClear,
data: $.map(data, function (d) {
d.id = d.$idField;
d.text = d.$textField;
return d;
})
}).trigger('change');
});
});
$('{$this->getElementClassSelector()}').trigger('change');
EOT;
添加
$('{$this->getElementClassSelector()}').trigger('change');
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: