Commit 49aca914 by huangqy

全选加取消

parent 85f4ce7a
......@@ -4,6 +4,7 @@ import { pzlx_dict } from '@ohos/common'
@Component
export struct WzInList {
@ObjectLink item: WzinClass
@Link checkedList: Array<string>
renderPzlx(pzlx) {
return pzlx_dict.find(v => v.value == pzlx).text
......@@ -14,7 +15,7 @@ export struct WzInList {
Row() {
Checkbox({ name: 'checkbox1', group: 'checkboxGroup' })
.selectedColor('#007DFF')
.select(this.item.checked)
.select(this.checkedList.includes(this.item.guid))
.onChange((value: boolean) => {
console.info('Checkbox1 change is' + value)
}).margin({ right: 10, left: 10 })
......
......@@ -25,6 +25,7 @@ export struct WzInPage {
@State selectedFontColor: string = '#fff'
@State currentIndex: number = 0
@State dataSource: WzinClass[] = []
@State checkedList: Array<string> = []
private controller: TabsController = new TabsController()
private searchcontroller: SearchController = new SearchController()
......@@ -136,21 +137,12 @@ export struct WzInPage {
Button("全选")
.bottomBtnSty().fontColor("#0fa983") .fontSize("14vp")
.onClick(() => {
promptAction.showToast({
message: '进来了' + this.dataSource.length
})
this.dataSource = this.dataSource.map((item) => {
return {
checked: true,
...item
}
})
Logger.info('全选:' + this.dataSource.length, JSON.stringify(this.dataSource))
this.checkedList = this.dataSource.map((item) => item.guid)
})
Button("清空选择")
.bottomBtnSty()
.onClick(() => {
this.checkedList = []
}).fontColor("#0fa983").fontSize("14vp")
}
}.height(80)
......@@ -230,10 +222,10 @@ export struct WzInPage {
List({ space: 2}) {
ForEach(this.dataSource, (item) => {
ListItem() {
WzInList({ item }).width('100%').backgroundColor('#fff')
WzInList({ item, checkedList: $checkedList }).width('100%').backgroundColor('#fff')
}
})
}.padding(20)
}.padding(18)
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论