php - Laravel-admin 中网格的 RowAction 使用相同的类标识符。如何为每一行设置唯一的类标识符的生成?
问题描述
有一个自定义按钮类(从Encore\Admin\Actions\RowAction 扩展)。
该类有一个确认窗口,其中包含每行的唯一信息。
/ **
* @return void
* /
public function dialog()
{
$model = Categories::where('id',$this->getKey())->with('users')->get();
$this->question(trans('admin.delete_confirm'), 'Comment:'.$model[0]->comment, ['confirmButtonColor' => '#d33']);
}
当脚本形成调用对话框时,它们具有相同的类标识符(例如,“. grid-row-action-5dca9548c28226038 ”),但文本不同。
...
$ ('.grid-row-action-5dca9548c28226038').off('click').on('click', function() {
...
"text": "Comment: text 1",
...
}
$ ('.grid-row-action-5dca9548c28226038').off('click').on('click', function() {
...
"text": "Comment: text 2",
...
}
$ ('.grid-row-action-5dca9548c28226038').off('click').on('click', function() {
...
"text": "Comment: text 3",
...
}
...
如何让 Laravel 管理员为每一行生成一个唯一标识符?
解决方案
解决方案是重写获取选择器的方法。
/**
* @var bool
*/
protected $multiplePrefix = true;
...
/**
* @param string $prefix
*
* @return mixed|string
*/
public function selector($prefix)
{
if (isset($this->multiplePrefix)){
return $this->getOptionalPrefix($prefix);
} elseif (is_null($this->selector)) {
return static::makeSelector(get_called_class(), $prefix);
}
return $this->selector;
}
/**
* @param $prefix
* @return string
*/
protected function getOptionalPrefix($prefix)
{
if (is_null($this->selector)) {
$this->selector = uniqid($prefix) . mt_rand(1000, 9999);
}
return $this->selector;
}
推荐阅读
- python - Python setuptools LINK:致命错误 LNK1181:无法打开输入文件“C:\Program.obj”
- android - GetCurrentLocation 在调试中工作,但在 Android 的发布 apk 中不起作用
- python - 如何将csv文件复制到字典中?
- javascript - 在 React JS 中使用动态数字键循环
- ignite - 禁用缓存的持久性
- assembly - 为什么写入可写 .data 部分时出现段错误?使用 Ubuntu、x86、nasm、gdb、readelf
- python - 根据分隔符拆分列值(熊猫)
- python - 如何对包含嵌套列表的列表进行排序,该列表还包含字典。目的是按字典 VALUE 对主列表进行排序
- excel - 为什么具有相同日期的单元格具有不同的日期序列号?
- python - 如何避免多次加载模块?