简体   繁体   English

用以前的数据填充表格

[英]Populate form with previous data

I'm looking to add a feature to my application which currently, you enter your first name and last name and a few other details. 我正在寻找一个功能添加到我的应用程序中,当前,您输入您的名字和姓氏以及其他一些详细信息。

What I want to add is the ability to start typing the first name in the form and instantly output those with a similar name and if the name is there then use those details rather than entering the name again. 我要添加的功能是能够开始在表单中输入名字,并立即输出具有类似名字的名字,如果名字在那里,则使用这些详细信息,而不必再次输入名字。

Once you've selected the name of a previous entry you can carry on adding the data to the form for the fields not populated. 选择上一个条目的名称后,可以继续将数据添加到未填充字段的表单中。

I'm currently working with laravel any insight to tackling this one would be greatly appreciated. 我目前正在与laravel合作,对解决这一问题的任何见解将不胜感激。

Thanks 谢谢

I have done this before but not in Laravel. 我之前已经做过,但在Laravel中还没有。 The concepts should be mostly the same. 概念应大致相同。 The issue you will run into is how you want to qualify similar. 您将遇到的问题是您希望如何获得类似的资格。 If similar means you can use a "like" query against values the start with what has been typed against a database table, it's super easy. 如果采用类似的方式,您可以对值使用“喜欢”查询(从针对数据库表键入的值开始),这非常容易。 The simple way is going to perform a query like this: 简单的方法是执行如下查询:

$users = DB::table('users')
            ->where('name', 'like', 'rob%')
            ->get();

Because the wildcard is at the end, you can still use a standard database index to prevent your lookups from killing your database. 由于通配符在末尾,因此您仍然可以使用标准数据库索引来防止您的查询杀死数据库。

If you want something more advanced, you'll have to figure out indexing schemes and possibly use a full-text index server like Lucene . 如果您需要更高级的功能,则必须找出索引方案,并可能使用像Lucene这样的全文本索引服务器。 We ended up with the latter. 我们最终选择了后者。

In either case, you will need an API endpoint that works with a front-end widget. 无论哪种情况,您都需要一个与前端窗口小部件一起使用的API端点。 I believe we used the JQuery plugin Select2 . 我相信我们使用了JQuery插件Select2 It has an example to make it work for a remote data set with Ajax. 它有一个示例,使其可以与Ajax一起用于远程数据集。

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

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