javascript 실시 간 검색 노드 절 류

970 단어 자바 script
let timeout
export const asyncReadSelect = (fileLabelValue, callback, needLable = false) => {
  return new Promise((resolve) => {
    if (timeout) {
      clearTimeout(timeout)
      timeout = null
    }
    timeout = setTimeout(() => {
      callback().then((result) => {
        const data = []
        result.forEach((r) => {
          data.push({
            label: r[fileLabelValue[0]],
            // value: r[fileLabelValue[1]]
            value: needLable ? `${r[fileLabelValue[0]]},${r[fileLabelValue[1]]}` : r[fileLabelValue[1]]
          })
        })
        resolve(data)
      })
    }, 300)
  })
}

호출
 getProductNameEffects = async (value) => {
    const getProductNameData = await asyncReadSelect(['productName', 'productName'], () => {
      return Api.Search({ productName: value.replace(/[']/g, '') })
    })
    return getProductNameData
  }

좋은 웹페이지 즐겨찾기