有一个自定义按钮类(从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;
}
$grid->disableRowSelector();