鸿蒙 - 查询
·
// 模糊查询
@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%')
}
}

更多推荐



所有评论(0)