SwiftUI –如何通过单击列表项来更改@State属性?

时间:2019-06-28 21:10:09

标签: swiftui

在我的列表中,我有一些静态项目。我想在用户点击另一个列表项时动态隐藏/显示一个项目,即当用户点击特定列表项时我想更改@State属性。

我该怎么做?

struct EditTransactionView : View {
    @State var date = Date()
    @State private var showingDateSelector = false // How do I change this with a tap on the date list item?

    var body: some View {
        NavigationView {
            List {
                DateView(date: $date)
                if showingDateSelector {
                    DatePicker(
                        $date,
                        maximumDate: Date(),
                        displayedComponents: .date )
                }
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

类似这样的东西:

def create_opportunity(self, data):
    r = requests.post(self.URL + 'sales/opportunities', json=data, headers=self.Header)
    r.raise_for_status()
    return r.json()

create_opp = {
    "name": "My Opportunity", 
    "primarySalesRep": {"name": "John Doe"},  # maybe "id" or "identifier" is required? 
    "company": {"name": "My Company"},  # maybe "id" or "identifier" is required? 
    "contact": {"name": "Jane Doe"},
}

opportunity = objCW.create_opportunity(create_opp)