link name link autocomplete搜索

发布于 2025-01-22 10:06:05 字数 1037 浏览 3 评论 0 原文

我想单击搜索框中的名称和该人的打开个人资料。如何在此项目上添加链接。firstName。我对用户配置文件的路线是'/user/{id}'..

这是我的JavaScript代码,用于autocomplete

<script type="text/javascript">
        $('.livesearch').select2({
            placeholder: 'Search users',
            ajax: {
                url: '/master/autocomplete',
                dataType: 'json',
                delay: 250,
                processResults: function (data) {
                    return {
                        results: $.map(data, function (item) {
                            return {
                                text: item.firstname+' '+item.lastname,
                                id: item.id,

                            }
                        })
                    };
                },
                cache: true,
            }
        });
    </script>

<< img src =“ https://i.sstatic.net/bvrsb.png” alt =“在此处输入图像说明”>

I want to click on name in search box and open profile of that person. How can I add link on this item.firstname. My route for user profile is '/users/{id}'..

this is my javascript code for autocomplete

<script type="text/javascript">
        $('.livesearch').select2({
            placeholder: 'Search users',
            ajax: {
                url: '/master/autocomplete',
                dataType: 'json',
                delay: 250,
                processResults: function (data) {
                    return {
                        results: $.map(data, function (item) {
                            return {
                                text: item.firstname+' '+item.lastname,
                                id: item.id,

                            }
                        })
                    };
                },
                cache: true,
            }
        });
    </script>

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

等待圉鍢 2025-01-29 10:06:05

不知道它是否有效,但是您可以尝试添加标签,而不是像

text: `<a href='/users/item.id'>${item.firstname} ${item.lastname}</a>`

Don't know if it works but you can try adding a tag instead of text like

text: `<a href='/users/item.id'>${item.firstname} ${item.lastname}</a>`
绮烟 2025-01-29 10:06:05

您可以尝试在选择选项时执行功能

$('select').on('select2:select', function (evt) {
   // get select value
  //page redirection
});

u can try executing a function on selecting the option

$('select').on('select2:select', function (evt) {
   // get select value
  //page redirection
});
同展鸳鸯锦 2025-01-29 10:06:05

有答案...我希望它对某人有帮助。

enter image description here

There is answer... I hope so that it can be helpful to someone..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文