Slide 10
Slide 10 text
macOS native 0VUMJOF7JFXJO4XJGU6*
©2024 1024jp
0VUMJOF7JFXJO4XJGU6*
List($items) { item in
ForEach($items) { item in
RowView(item: item)
}
}
Table(of: Binding.self) { item in
TableColumn("Name") {
TextField(text: item.name, label: EmptyView.init)
}
} rows: {
RecursiveTableRows(items: $items)
}
List($items, children: \.children) { item in
TextField(text: item.name, label: EmptyView.init)
}
List {
OutlineGroup($items, children: \.children) { item in
TextField(text: item.name, label: EmptyView.init)
}
}
Table(self.items, children: \.children) { item in
TableColumn("Name", value: \.name) {
Text(item.name)
}
}
-JTUܥ 5BCMFܥ
private struct RowView: View {
@Binding var item: Item
var body: some View {
if let children = Binding<[Item]>($item.children) {
DisclosureGroup(isExpanded: $item.isExpanded) {
ForEach(children) { child in
RowView(item: child)
}
} label: {
TextField(text: $item.name, label: EmptyView.init)
}
} else {
TextField(text: $item.name, label: EmptyView.init)
}
}
}
private struct RecursiveTableRows: TableRowContent {
@Binding var items: [Item]
var tableRowBody: some TableRowContent> {
ForEach($items) { item in
if let children = Binding(item.children) {
DisclosureTableRow(item, isExpanded: item.isExpanded) {
RecursiveTableRows(children)
}
} else {
TableRow(item)
}
}
}
}