9

savedDataTypeAhead - CodeSandbox

 4 years ago
source link: https://codesandbox.io/s/saveddatatypeahead-lcyfg?file=%2Fsrc%2Findex.js
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

savedDataTypeAhead - CodeSandbox

File
Edit
Selection
View
Go
Help
Sandbox Info
Files
index.js
styles.css
index.html
package.json
Dependencies
// - 给出一个对象数组, 里面有 name 和 email 两个字段, 输入 input, 然后返回所有匹配项.  √
// - 查找的复杂度 N x M x K √
// - 然后将筛选后的对象数组, 渲染到 HTML 上  √
// - 如何不让这个 dropdown 影响之后的文档布局.
// - 如果数组非常大, 如何优化查找速度.√ treemap / sort
// - 如果用户频繁输入, 如何优化.√
// How to make the search more efficient
// right now the time complexity for the search is O(N x M x K)
const endpoint =
  "https://gist.githubusercontent.com/Miserlou/c5cd8364bf9b2420bb29/raw/2bf258763cdddd704f8ffd3ea9a3e81d25e2c6f6/cities.json";
const searchInput = document.querySelector(".type-ahead__input");
const resultsContainer = document.querySelector(
  ".type-ahead__result-container"
const data = [];
fetch(endpoint)
  .then(res => res.json())
  .then(result => {
    data.push(...result);

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK