Dcat Admin 怎么通过 JS 动态更新 multipleSelectTable的选中内容
1. 运行环境
1). 当前使用的 Laravel 版本?
//: <Laravel Framework 6.20.44> (使用 php artisan --version
命令查看)
2). 当前使用的 php/php-fpm 版本?
PHP 版本:
//: <PHP 7.3.29> (使用 php --version
命令查看 php 版本)
php-fpm 版本:
3). 当前系统
//: <CentOS 8> (期待数值 Windows 10 / Ubuntu 20.4 / CentOS 8 )
4). 业务环境
5). 相关软件版本
//: <Nginx 、MySQL> (提供相关软件的版本,如 Nginx 、MySQL、MongoDB 等)
2. 问题描述?
//: <我现在是想通过下拉选择动态用 JS从服务器获取数据类似[‘173’,’192’]的数据更新到multipleSelectTable,可是无法正常显示>
$form->select(‘selectcardno’,’选择卡’)
->options(Key::get_userkey_all($this->uid)->pluck(‘disp’,’keyid’))->default(‘0’);
$form->multipleSelectTable(‘devicegroupid’, ‘权限’)
->title(‘权限组’)
->max(10)
->from(LiftGroupTable::make())
->model(LiftDevicegroup::class, ‘devicegroupid’, ‘devicegroupname’)
->customFormat(function ($v) {
if (!$v) return [];
return array_column($v, ‘id’);
});
Admin::script(
<<<JS
(function () {
$(‘select[name=”selectcardno”]’).on(‘change’, function () {//通过点击获取的值
if($(this).val()){
$(“input[name=’keyid’]”).val($(this).val());
$.ajax({
‘type’ : ‘get’,
‘url’ : ‘/admin/key’,
‘data’ : {keyid:$(this).val()},
‘dataType’ : ‘json’,
success : function(res){
//返回的数据格式类似[‘173’,’192’]
$(“input[name=’devicegroupid’]”).val((res[0][‘devicegroups’]);
}
});
}
});
})();
JS
);
推荐文章: