简体   繁体   English

来自PHP数组变量的HTML输入动态过滤?

[英]HTML input dynamic filtering from PHP array variable?

I have a score entry page on a PHP-based website.我在基于 PHP 的网站上有一个分数输入页面。 It uses a DB query to retrieve the player's Name & DB ID into a PHP array variable, then loops around the returned data to create an HTML <select> dropdown list.它使用 DB 查询将玩家的名称和 DB ID 检索到 PHP 数组变量中,然后循环返回的数据以创建 HTML <select>下拉列表。

This has now become too long… especially when entering on a mobile device (on iOS its even worse with that scroll wheel implementation they use - I dont even know what it looks like on Android!)现在已经变得太长了……尤其是在移动设备上输入时(在 iOS 上,他们使用的滚轮实现更糟糕 - 我什至不知道它在 Android 上的样子!)

So I have a PHP array with the Name & ID fields in it.所以我有一个 PHP 数组,其中包含名称和 ID 字段。

I would like to convert this to filter a dynamic dropdown list as characters are typed in by the user.当用户输入字符时,我想将其转换为过滤动态下拉列表。

I am novice at Javascript and it's nuances, though understand the principles of the language.我是 Javascript 的新手,虽然了解语言的原理,但它的细微差别。 The DOM model and other things I am also not very familiar with. DOM模型等东西我也不是很熟悉。 I expect to use an onChange() function on the <input> textbox(?).我希望在<input>文本框(?)上使用onChange()函数。

But how do I either tie that back to my existing PHP array variable?但是我如何将它与我现有的 PHP 数组变量联系起来呢? Or copy this variable “across” to the JS function?或者将这个变量“跨越”复制到 JS 函数中?

I have changed the underlying DB to a NoSQL version (MongoDB).我已将底层数据库更改为 NoSQL 版本(MongoDB)。 The bulk of tutorials, blogs, etc, for “AJAX Live Search” or equivalent seem to be centred around MySQL (which I previously used…) “AJAX 实时搜索”或等效的大部分教程、博客等似乎都以 MySQL 为中心(我以前使用过……)

The esiest approach would be usage of some js library, which can do what you need.最简单的方法是使用一些 js 库,它可以满足您的需求。

In my experience this should work for you: https://selectize.dev/以我的经验,这应该适合你: https ://selectize.dev/

It combines select with text input, where text input is only used to seach in the select and hides unmatching records from it.它将选择与文本输入相结合,其中文本输入仅用于在选择中搜索并隐藏不匹配的记录。

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

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