Commit 49aca914 by huangqy

全选加取消

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