我收到错误消息
Value of type '[Voucher]' has no member 'currency'.
Value of type '[Voucher]' has no member 'shopName'.
Value of type '[Voucher]' has no member 'value'.
在这里我得到了错误(ContentView):
@ObservedObject var voucherData = VoucherData()
var body: some View {
NavigationView {
ZStack {
List(voucherData.voucherList) { voucher in
NavigationLink(destination: EditView(value: self.$voucherData.voucherList.value, currency: self.$voucherData.voucherList.currency, shopName: self.$voucherData.voucherList.shopName)) {
VStack() { ...
在另一个文件中,定义了列表:
import SwiftUI
import Combine
struct Voucher : Identifiable {
var value : String = ""
var currency : String = ""
var shopName : String = ""
}
final class VoucherData: ObservableObject {
@Published var voucherList: [Voucher] = [
.init(value: "20", currency: "USD", shopName: "FlyBurger")]
}
答案 0 :(得分:0)
这是因为您尝试访问数组而不是单个对象,所以将代码更改为
<a href="so.php?edit=' . $row['sonum'] . '" class="btn btn-info">Edit</a>
也就是说,由于List遍历给定的数组var body: some View {
NavigationView {
ZStack {
List(voucherData.voucherList) { voucher in
NavigationLink(destination: EditView(value: voucher.value, currency: voucher.currency, shopName: voucher.shopName)) {
VStack() { ...
,并将每个元素作为参数发送给闭包voucherData.voucherList
,因此您应该在闭包内使用该参数