// 模糊查询
@Entry
@Component
struct Day1_d {
  @State arr: string[] = ['电视', '洗衣机', '空调', '电冰箱', '手机', '电脑']
  @State str: string = ''
  @State temp: string[] = []

  build() {
    Column() {
      Row() {
        TextInput().layoutWeight(1).onChange((value) => {
          this.str = value
        })
        Button('模糊查询').onClick((event: ClickEvent) => {
          // let temp: string[] = []
          for (let t of this.arr) {
            if (t.includes(this.str)) {
              this.temp.push(t)
            }
          }
          console.log('', this.temp)
        })
        Button('精准查询').onClick((event: ClickEvent) => {
          console.log('',this.arr.indexOf(this.str))
        })
      }
    }
    .height('100%')
    .width('100%')
  }
}

Logo

讨论HarmonyOS开发技术,专注于API与组件、DevEco Studio、测试、元服务和应用上架分发等。

更多推荐