简体   繁体   English

复制到 Larvel Orchid 列的剪贴板

[英]Copy to Clipboard for Larvel Orchid Column

I have a question if someone else was in this kind of situation maybe they have a solution, for Laravel Orchid im trying to make a Copy to Clipboard Button for the Column Name with the clipboard.js.我有一个问题,如果其他人处于这种情况下,也许他们有解决方案,因为 Laravel Orchid 我正在尝试使用 clipboard.js 为列名称创建一个复制到剪贴板按钮。 I didn't get how to use it with Laravel Orchid for other Projects it was okay.我不知道如何将它与 Laravel Orchid 一起用于其他项目,没关系。

my layout looks like this:我的布局是这样的:

...
protected function columns(): array
    {
        return [
            TD::make('name', 'Name')
                ->render(function ($item) {
                    return
                        Group::make([
                            Link::make($item->name)->route('platform.item.show', $item),
                            Button::make('myBtn')->id('#myBtn')
                        ]);
                })->sort(),
    ....

but with the click on the button im getting only an error:但是点击按钮我只得到一个错误:

TypeError
Argument 1 passed to Orchid\Screen\Screen::callMethod() must be of the type string, null given, called in /Volumes/T5/www/inventory-manager-laravel/vendor/orchid/platform/src/Screen/Screen.php on line 179

what i want is i have in my script.js a function which listening to this id and using then the clipboard js, is there a better way for achieving my goal what am i doing wrong?我想要的是我的 script.js 中有一个函数,它监听这个 id 然后使用剪贴板 js,有没有更好的方法来实现我的目标我做错了什么?

Thanks in advance提前致谢

Jaba , as far as I understand, the button must have a method Jaba ,据我所知,按钮必须有一个方法

Button::make('myBtn')->id('#myBtn')->method('foo') . Button::make('myBtn')->id('#myBtn')->method('foo') Doc文档

method('methodName') – when clicked, the form will be sent to the specified method within the current screen method('methodName') – 单击时,表单将发送到当前屏幕中的指定方法

So, you could use Link::make('myBtn')->id('#myBtn') and style it with ->class('foo-class') .因此,您可以使用Link::make('myBtn')->id('#myBtn')并使用->class('foo-class')设置样式。 Total: Link::make('myBtn')->class('btn btn-primary')->id('#myBtn') ;总计: Link::make('myBtn')->class('btn btn-primary')->id('#myBtn') ;

I couldn't figure a good way out, for now I came up with a quick and dirty solution which is fine for now, but not the way it should be:我想不出一个好的出路,现在我想出了一个快速而肮脏的解决方案,目前还不错,但不是应该的方式:

TD::make( 'name', 'Name')
    ->render(function ($item) {
        return Group::make([
            $item->name,
            Link::make()
                ->route('platform.item.show', $item)
                    ->icon('action-redo')
                         ->id('myBtn')
                              ->type(Color::INFO()),
                        ])->autoWidth();
                    }),

I'm returning the name as string so the user can copy it and add a button to go to the actual page itself.我将名称作为字符串返回,以便用户可以复制它并添加一个按钮以转到实际页面本身。

For what I try to get the actual copy to clipboard is:对于我尝试将实际副本复制到剪贴板的是:

I added in the same class following ( I couldn't copy my code without loosing the formatting sorry for the image )我在同一类中添加了以下内容(我无法在不丢失图像格式的情况下复制我的代码

在此处输入图像描述

and in the column I build it like this:在专栏中,我是这样构建的:

    TD::make( 'name', 'Name')
                ->render(function ($item) {
                    $value = $item->name;
                    $button = '<button id="myBtn" class="btn btn-secondary" data-clipboard-text="'.$value.'">Copy</button>';
                    return Group::make([
                        $button,
                        $item->name,
                    ])->autoWidth();
                }),

I also try now to get the clipboard.js with cdn instead of installing it with no success我现在也尝试使用 cdn 获取 clipboard.js 而不是安装它但没有成功

The second method was with jQuery like Multi_Pony suggested but only the 1st element is seen and working with this:第二种方法是像 Multi_Pony 建议的那样使用 jQuery,但只看到第一个元素并使用它:

$("#myBtn").click(function(){
    alert("The paragraph was clicked.");
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM